Utility docs
Look up any call, event, or storage item with code examples. Runtime v490 · Block #9,478,217
Developer documentation for the Utility 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.
Utility
Send a batch of dispatch calls.
Calls 10
Sends multiple calls in a batch, continuing on failure.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
calls | Vec<RuntimeCall> | Array of RuntimeCall | calls (Vec<RuntimeCall>) |
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 batch call (typed, named args)
const calls = [] as [];
const tx = api.tx.Utility.batch({
calls,
});Executes a call as a derivative account of the sender.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
index | u16 | Integer (0-65535) | index (u16) |
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 as_derivative call (typed, named args)
const index = 0;
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Utility.as_derivative({
index,
call,
});Sends multiple calls atomically, reverting all on any failure.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
calls | Vec<RuntimeCall> | Array of RuntimeCall | calls (Vec<RuntimeCall>) |
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 batch_all call (typed, named args)
const calls = [] as [];
const tx = api.tx.Utility.batch_all({
calls,
});Dispatches a call with a specified origin (root only).
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
as_origin | OriginCaller | — | as_origin (OriginCaller) |
call | RuntimeCall | — | call (RuntimeCall) |
// ----------------------------------------------------------------------
// HEADS UP: 2 args below have a complex type with no usable default.
// Look for `undefined as any` and replace them with real values
// 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 dispatch_as call (typed, named args)
const as_origin = undefined as any /* OriginCaller — replace with real value */;
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Utility.dispatch_as({
as_origin,
call,
});Sends multiple calls, ignoring failures entirely.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
calls | Vec<RuntimeCall> | Array of RuntimeCall | calls (Vec<RuntimeCall>) |
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 force_batch call (typed, named args)
const calls = [] as [];
const tx = api.tx.Utility.force_batch({
calls,
});Dispatches a call with a specified weight (root only).
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
call | RuntimeCall | — | call (RuntimeCall) |
weight | Weight | Execution Weight | weight: Substrate dispatch weight (computational cost) |
// ----------------------------------------------------------------------
// HEADS UP: 2 args below have a complex type with no usable default.
// Look for `undefined as any` and replace them with real values
// 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 with_weight call (typed, named args)
const call = undefined as any /* RuntimeCall — replace with real value */;
const weight = undefined as any /* Weight — replace with real value */;
const tx = api.tx.Utility.with_weight({
call,
weight,
});Executes fallback call if main call fails.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
main | RuntimeCall | — | main (RuntimeCall) |
fallback | RuntimeCall | — | fallback (RuntimeCall) |
// ----------------------------------------------------------------------
// HEADS UP: 2 args below have a complex type with no usable default.
// Look for `undefined as any` and replace them with real values
// 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 if_else call (typed, named args)
const main = undefined as any /* RuntimeCall — replace with real value */;
const fallback = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Utility.if_else({
main,
fallback,
});Dispatches a call as a different origin, forwarding any errors (root only).
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
as_origin | OriginCaller | — | as_origin (OriginCaller) |
call | RuntimeCall | — | call (RuntimeCall) |
// ----------------------------------------------------------------------
// HEADS UP: 2 args below have a complex type with no usable default.
// Look for `undefined as any` and replace them with real values
// 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 dispatch_as_fallible call (typed, named args)
const as_origin = undefined as any /* OriginCaller — replace with real value */;
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Utility.dispatch_as_fallible({
as_origin,
call,
});Registers the caller derivative account as a protected derived authority in HashedAccounts, then dispatches a call from it. The address is the same one Utility.as_derivative uses.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
index | u16 | Integer (0-65535) | index (u16) |
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 as_protected_derivative call (typed, named args)
const index = 0;
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Utility.as_protected_derivative({
index,
call,
});Dispatches a call from a derivative account whose 32-byte id is a domain-separated blake2_256 hash that is neither an Ed25519 nor a Ristretto point.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
index | u16 | Integer (0-65535) | index (u16) |
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 as_safe_derivative call (typed, named args)
const index = 0;
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Utility.as_safe_derivative({
index,
call,
});Events 8
Emitted when a batch did not complete fully - gives index of first failing call.
When it fires
- batch or batch_all call executed
- At least one inner call failed
Fields
| Name | Type | Format | Description |
|---|---|---|---|
index | u32 | Integer | Index of the first failing call in the batch |
error | DispatchError | Dispatch Error | Error that caused the batch to be interrupted |
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 BatchInterrupted events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Utility.BatchInterrupted.get(block.hash);
for (const evt of events) {
console.log("BatchInterrupted:", evt.payload);
}
});Emitted when all calls in a batch completed successfully.
When it fires
- batch, batch_all, or force_batch call executed
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 BatchCompleted events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Utility.BatchCompleted.get(block.hash);
for (const evt of events) {
console.log("BatchCompleted:", evt.payload);
}
});Emitted when a batch completed but some calls failed.
When it fires
- force_batch call executed
- At least one call failed
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 BatchCompletedWithErrors events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Utility.BatchCompletedWithErrors.get(block.hash);
for (const evt of events) {
console.log("BatchCompletedWithErrors:", evt.payload);
}
});Emitted for each call in a batch that completed successfully.
When it fires
- Part of a batch execution
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 ItemCompleted events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Utility.ItemCompleted.get(block.hash);
for (const evt of events) {
console.log("ItemCompleted:", evt.payload);
}
});Emitted for each call in a batch that failed.
When it fires
- Part of force_batch
- This call failed
Fields
| Name | Type | Format | Description |
|---|---|---|---|
error | DispatchError | Dispatch Error | Error from the failed call |
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 ItemFailed events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Utility.ItemFailed.get(block.hash);
for (const evt of events) {
console.log("ItemFailed:", evt.payload);
}
});Emitted when a call was dispatched with a different origin.
When it fires
- dispatch_as called by root
Fields
| Name | Type | Format | Description |
|---|---|---|---|
result | Result | — | Result of the dispatched call (Ok or Err) |
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 DispatchedAs events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Utility.DispatchedAs.get(block.hash);
for (const evt of events) {
console.log("DispatchedAs:", evt.payload);
}
});Emitted when the main call in if_else succeeded.
When it fires
- if_else call executed
- Main call succeeded
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 IfElseMainSuccess events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Utility.IfElseMainSuccess.get(block.hash);
for (const evt of events) {
console.log("IfElseMainSuccess:", evt.payload);
}
});Emitted when the main call failed and fallback was executed.
When it fires
- if_else executed
- Main failed
Fields
| Name | Type | Format | Description |
|---|---|---|---|
main_error | DispatchError | Dispatch Error | Error from the main call that triggered fallback |
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 IfElseFallbackCalled events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Utility.IfElseFallbackCalled.get(block.hash);
for (const evt of events) {
console.log("IfElseFallbackCalled:", evt.payload);
}
});Constants 1
Maximum number of calls that can be batched in a single transaction.
u3210922import { 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 batched_calls_limit constant
const value = await api.constants.Utility.batched_calls_limit();
console.log("batched_calls_limit:", value);Errors 3
The batch exceeds the maximum number of calls allowed.
Common Causes
- Batch contains more calls than batched_calls_limit allows
- Trying to batch too many operations in a single transaction
How to Fix
Check the batched_calls_limit constant for the maximum,Split your batch into multiple smaller batches
The derivative account index is invalid or cannot be computed.
Common Causes
- Invalid index value provided to as_derivative
- Account derivation failed
How to Fix
Ensure index is a valid u16 value (0 to 65535),Check that the account derivation produces a valid address
Utility.as_safe_derivative could not derive a child account for (caller, index). Either all 64 candidate hashes decode as an Ed25519 or Ristretto point, or the chosen 32 bytes do not round-trip as the runtime AccountId.
Common Causes
- Every attempt 0 to 63 of blake2_256(SCALE("subtensor/safe-derivative/v1", (caller, index)) ++ attempt) decompresses as a CompressedEdwardsY or CompressedRistretto point
How to Fix
Call Utility.as_safe_derivative with a different index. The index is part of the hashed manifest, so it yields an independent set of 64 candidates