Scheduler docs
Look up any call, event, or storage item with code examples. Runtime v472 · Block #9,197,056
Developer documentation for the Scheduler pallet of the Subtensor blockchain, part of the Bittensor decentralized AI network. This page is designed for developers integrating with the chain: look up any call, event, or storage item, copy code examples in TypeScript, Python, or Rust, and filter by your role. For in-depth explanations, version history, and relationships between items, see the Reference section.
Scheduler
See [`Pallet::schedule`].
Calls 10
Anonymously schedule a call for future execution at a specific block.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
when | u32 | Integer | when: Block number |
maybe_periodic | Option | — | maybe_periodic (Option) |
priority | u8 | Integer (0-255) | priority (u8) |
call | RuntimeCall | — | call (RuntimeCall) |
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build schedule call (typed, named args)
const when = 0;
const maybe_periodic = undefined;
const priority = 0;
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Scheduler.schedule({
when,
maybe_periodic,
priority,
call,
});Cancel an anonymously scheduled task by its block and index.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
when | u32 | Integer | when: Block number |
index | u32 | Integer | index (u32) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build cancel call (typed, named args)
const when = 0;
const index = 0;
const tx = api.tx.Scheduler.cancel({
when,
index,
});Schedule a named task for future execution with a unique identifier.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
id | [u8; 32] | — | id ([u8; 32]) |
when | u32 | Integer | when: Block number |
maybe_periodic | Option | — | maybe_periodic (Option) |
priority | u8 | Integer (0-255) | priority (u8) |
call | RuntimeCall | — | call (RuntimeCall) |
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build schedule_named call (typed, named args)
const id = "0x0000000000000000000000000000000000000000000000000000000000000000";
const when = 0;
const maybe_periodic = undefined;
const priority = 0;
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Scheduler.schedule_named({
id,
when,
maybe_periodic,
priority,
call,
});Cancel a scheduled task by its unique name identifier.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
id | [u8; 32] | — | id ([u8; 32]) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build cancel_named call (typed, named args)
const id = "0x0000000000000000000000000000000000000000000000000000000000000000";
const tx = api.tx.Scheduler.cancel_named({
id,
});Anonymously schedule a task to execute after a delay from the current block.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
after | u32 | Integer | after: Block number |
maybe_periodic | Option | — | maybe_periodic (Option) |
priority | u8 | Integer (0-255) | priority (u8) |
call | RuntimeCall | — | call (RuntimeCall) |
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build schedule_after call (typed, named args)
const after = 0;
const maybe_periodic = undefined;
const priority = 0;
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Scheduler.schedule_after({
after,
maybe_periodic,
priority,
call,
});Schedule a named task to execute after a delay from the current block.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
id | [u8; 32] | — | id ([u8; 32]) |
after | u32 | Integer | after: Block number |
maybe_periodic | Option | — | maybe_periodic (Option) |
priority | u8 | Integer (0-255) | priority (u8) |
call | RuntimeCall | — | call (RuntimeCall) |
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build schedule_named_after call (typed, named args)
const id = "0x0000000000000000000000000000000000000000000000000000000000000000";
const after = 0;
const maybe_periodic = undefined;
const priority = 0;
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Scheduler.schedule_named_after({
id,
after,
maybe_periodic,
priority,
call,
});Configure retry behavior for a scheduled task if it fails.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
task | (u32, u32) | — | task ((u32, u32)) |
retries | u8 | Integer (0-255) | retries (u8) |
period | u32 | Integer | period: Block number |
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build set_retry call (typed, named args)
const task = undefined as any /* (u32, u32) — replace with real value */;
const retries = 0;
const period = 0;
const tx = api.tx.Scheduler.set_retry({
task,
retries,
period,
});Configure retry behavior for a named scheduled task.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
id | [u8; 32] | — | id ([u8; 32]) |
retries | u8 | Integer (0-255) | retries (u8) |
period | u32 | Integer | period: Block number |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build set_retry_named call (typed, named args)
const id = "0x0000000000000000000000000000000000000000000000000000000000000000";
const retries = 0;
const period = 0;
const tx = api.tx.Scheduler.set_retry_named({
id,
retries,
period,
});Remove the retry configuration from a scheduled task.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
task | (u32, u32) | — | task ((u32, u32)) |
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build cancel_retry call (typed, named args)
const task = undefined as any /* (u32, u32) — replace with real value */;
const tx = api.tx.Scheduler.cancel_retry({
task,
});Remove the retry configuration from a named scheduled task.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
id | [u8; 32] | — | id ([u8; 32]) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Build cancel_retry_named call (typed, named args)
const id = "0x0000000000000000000000000000000000000000000000000000000000000000";
const tx = api.tx.Scheduler.cancel_retry_named({
id,
});Events 10
Emitted when a task is successfully scheduled for future execution.
When it fires
- Schedule call succeeded
- Agenda had capacity at target block
Fields
| Name | Type | Format | Description |
|---|---|---|---|
when | u32 | Integer | Block number when the task will execute |
index | u32 | Integer | Index of the task within the block's agenda |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to Scheduled events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Scheduler.Scheduled.get(block.hash);
for (const evt of events) {
console.log("Scheduled:", evt.payload);
}
});Emitted when a scheduled task is cancelled before execution.
When it fires
- Cancel call succeeded
- Task existed at specified position
Fields
| Name | Type | Format | Description |
|---|---|---|---|
when | u32 | Integer | Block number where the task was scheduled |
index | u32 | Integer | Index of the cancelled task within the block's agenda |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to Canceled events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Scheduler.Canceled.get(block.hash);
for (const evt of events) {
console.log("Canceled:", evt.payload);
}
});Emitted when a scheduled task is executed.
When it fires
- Block reached scheduled time
- Task existed in Agenda
Fields
| Name | Type | Format | Description |
|---|---|---|---|
task | (u32, u32) | — | Task address as (block_number, index) tuple |
id | Option | — | Optional 32-byte task name (None for anonymous tasks) |
result | Result | — | Dispatch result (Ok or Err with error details) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to Dispatched events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Scheduler.Dispatched.get(block.hash);
for (const evt of events) {
console.log("Dispatched:", evt.payload);
}
});Emitted when retry configuration is set for a scheduled task.
When it fires
- Task exists
- set_retry call succeeded
Fields
| Name | Type | Format | Description |
|---|---|---|---|
task | (u32, u32) | — | Task address as (block_number, index) tuple |
id | Option | — | Optional 32-byte task name (None for anonymous tasks) |
period | u32 | Integer | Number of blocks between retry attempts |
retries | u8 | Integer (0-255) | Maximum number of retry attempts allowed |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to RetrySet events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Scheduler.RetrySet.get(block.hash);
for (const evt of events) {
console.log("RetrySet:", evt.payload);
}
});Emitted when retry configuration is removed from a scheduled task.
When it fires
- Task had retry config
- cancel_retry call succeeded
Fields
| Name | Type | Format | Description |
|---|---|---|---|
task | (u32, u32) | — | Task address as (block_number, index) tuple |
id | Option | — | Optional 32-byte task name (None for anonymous tasks) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to RetryCancelled events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Scheduler.RetryCancelled.get(block.hash);
for (const evt of events) {
console.log("RetryCancelled:", evt.payload);
}
});Emitted when a periodic task fails to reschedule because the agenda is full.
When it fires
- Periodic task completed
- Next occurrence block agenda at capacity
Fields
| Name | Type | Format | Description |
|---|---|---|---|
task | (u32, u32) | — | Task address as (block_number, index) tuple |
id | Option | — | Optional 32-byte task name (None for anonymous tasks) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to PeriodicFailed events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Scheduler.PeriodicFailed.get(block.hash);
for (const evt of events) {
console.log("PeriodicFailed:", evt.payload);
}
});Emitted when a task retry fails to reschedule due to agenda capacity or weight.
When it fires
- Task failed and retry attempted
- Retry could not be scheduled
Fields
| Name | Type | Format | Description |
|---|---|---|---|
task | (u32, u32) | — | Task address of the failed retry attempt |
id | Option | — | Optional 32-byte task name (None for anonymous tasks) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to RetryFailed events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Scheduler.RetryFailed.get(block.hash);
for (const evt of events) {
console.log("RetryFailed:", evt.payload);
}
});Emitted when a task is permanently abandoned because it always exceeds weight limits.
When it fires
- Task execution exceeded available weight
- No possibility of success
Fields
| Name | Type | Format | Description |
|---|---|---|---|
task | (u32, u32) | — | Task address as (block_number, index) tuple |
id | Option | — | Optional 32-byte task name (None for anonymous tasks) |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to PermanentlyOverweight events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Scheduler.PermanentlyOverweight.get(block.hash);
for (const evt of events) {
console.log("PermanentlyOverweight:", evt.payload);
}
});Emitted when not all scheduled tasks could be processed in a block.
When it fires
- Block processing hit weight limit
- Remaining tasks exist
Fields
| Name | Type | Format | Description |
|---|---|---|---|
when | u32 | Integer | Block number where agenda processing was incomplete |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Subscribe to AgendaIncomplete events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Scheduler.AgendaIncomplete.get(block.hash);
for (const evt of events) {
console.log("AgendaIncomplete:", evt.payload);
}
});Storage 4
Items to be executed, indexed by the block number for execution.
BoundedVec Keys
| Name | Type | Format | Description |
|---|---|---|---|
key1 | u32 | Integer | — |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Query Agenda storage
const key1 = 0;
const result = await api.query.Scheduler.Agenda.getValue(key1);
console.log("Agenda:", result);Block number from which the agenda became incomplete.
u32 (Integer)import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Query IncompleteSince storage (no keys - plain value)
const result = await api.query.Scheduler.IncompleteSince.getValue();
console.log("IncompleteSince:", result);Lookup from a name to the block number and index of the task.
(u32, u32) Keys
| Name | Type | Format | Description |
|---|---|---|---|
key1 | [u8; 32] | — | — |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Query Lookup storage
const key1 = "0x0000000000000000000000000000000000000000000000000000000000000000";
const result = await api.query.Scheduler.Lookup.getValue(key1);
console.log("Lookup:", result);Retry configurations for items, indexed by task address (block, index).
RetryConfig Keys
| Name | Type | Format | Description |
|---|---|---|---|
key1 | u32 | Integer | — |
key2 | u32 | Integer | — |
import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Query Retries storage
const key1 = 0;
const key2 = 0;
const result = await api.query.Scheduler.Retries.getValue(key1, key2);
console.log("Retries:", result);Constants 2
Maximum weight for scheduled calls.
Weight"1369913486720630795"import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Query MaximumWeight constant
const value = await api.constants.Scheduler.MaximumWeight();
console.log("MaximumWeight:", value);Maximum scheduled calls per block.
u3250import { createClient, Binary } from "polkadot-api";
import { getWsProvider } from "polkadot-api/ws";
import { sub } from "@polkadot-api/descriptors"; // generated by: npx papi add sub -w wss://entrypoint-finney.opentensor.ai:443
const client = createClient(getWsProvider("wss://entrypoint-finney.opentensor.ai:443"));
const api = client.getTypedApi(sub);
// Query MaxScheduledPerBlock constant
const value = await api.constants.Scheduler.MaxScheduledPerBlock();
console.log("MaxScheduledPerBlock:", value);Errors 5
The runtime failed to schedule the requested call.
Common Causes
- Agenda for target block is full (MaxScheduledPerBlock reached)
- Insufficient weight budget for the block
- Invalid scheduling parameters
How to Fix
Try scheduling for a different block,Check MaxScheduledPerBlock constant,Reduce the number of scheduled tasks for that block
The scheduled call you're trying to cancel or modify doesn't exist.
Common Causes
- Task already executed
- Task already cancelled
- Wrong block number or index
- Wrong task name/id
How to Fix
Verify the task address (block, index) or name,Check Scheduler.Agenda storage for the target block,For named tasks, check Scheduler.Lookup storage
You're trying to schedule a call for a block that has already passed.
Common Causes
- Target block number is less than or equal to current block
- Delay calculation error
- Stale transaction submitted after target passed
How to Fix
Use a future block number,Use schedule_after with a positive delay,Recalculate target based on current block
The reschedule operation would not change the scheduled time.
Common Causes
- New target block equals current scheduled block
- Calling reschedule with same parameters
How to Fix
Provide a different target block number,Verify the task's current scheduled block before rescheduling
You used a non-named function on a named task, or vice versa.
Common Causes
- Using cancel on a named task (should use cancel_named)
- Using cancel_named on an anonymous task
- Task was created with schedule_named but modified with schedule
How to Fix
For named tasks: use cancel_named, set_retry_named, cancel_retry_named,For anonymous tasks: use cancel, set_retry, cancel_retry with (block, index),Check Scheduler.Lookup to verify if task has a name