All pallets

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.

Index: 11 22 items

Calls 10

batch

call details

Sends multiple calls in a batch, continuing on failure.

Parameters

NameTypeFormatDescription
callsVec<RuntimeCall>Array of RuntimeCallcalls (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,
});

as_derivative

call details

Executes a call as a derivative account of the sender.

Parameters

NameTypeFormatDescription
indexu16Integer (0-65535)index (u16)
callRuntimeCall—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,
});

batch_all

call details

Sends multiple calls atomically, reverting all on any failure.

Parameters

NameTypeFormatDescription
callsVec<RuntimeCall>Array of RuntimeCallcalls (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,
});

dispatch_as

call details

Dispatches a call with a specified origin (root only).

Parameters

NameTypeFormatDescription
as_originOriginCaller—as_origin (OriginCaller)
callRuntimeCall—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,
});

force_batch

call details

Sends multiple calls, ignoring failures entirely.

Parameters

NameTypeFormatDescription
callsVec<RuntimeCall>Array of RuntimeCallcalls (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,
});

with_weight

call details

Dispatches a call with a specified weight (root only).

Parameters

NameTypeFormatDescription
callRuntimeCall—call (RuntimeCall)
weightWeightExecution Weightweight: 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,
});

if_else

call details

Executes fallback call if main call fails.

Parameters

NameTypeFormatDescription
mainRuntimeCall—main (RuntimeCall)
fallbackRuntimeCall—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,
});

dispatch_as_fallible

call details

Dispatches a call as a different origin, forwarding any errors (root only).

Parameters

NameTypeFormatDescription
as_originOriginCaller—as_origin (OriginCaller)
callRuntimeCall—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,
});

as_protected_derivative

call details

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

NameTypeFormatDescription
indexu16Integer (0-65535)index (u16)
callRuntimeCall—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,
});

as_safe_derivative

call details

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

NameTypeFormatDescription
indexu16Integer (0-65535)index (u16)
callRuntimeCall—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

BatchInterrupted

event details

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

NameTypeFormatDescription
indexu32IntegerIndex of the first failing call in the batch
errorDispatchErrorDispatch ErrorError that caused the batch to be interrupted
Emitted by: batch/ batch_all
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);
  }
});

BatchCompleted

event details

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);
  }
});

BatchCompletedWithErrors

event details

Emitted when a batch completed but some calls failed.

When it fires

  • force_batch call executed
  • At least one call failed
Emitted by: force_batch/ batch
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);
  }
});

ItemCompleted

event details

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);
  }
});

ItemFailed

event details

Emitted for each call in a batch that failed.

When it fires

  • Part of force_batch
  • This call failed

Fields

NameTypeFormatDescription
errorDispatchErrorDispatch ErrorError from the failed call
Emitted by: force_batch
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);
  }
});

DispatchedAs

event details

Emitted when a call was dispatched with a different origin.

When it fires

  • dispatch_as called by root

Fields

NameTypeFormatDescription
resultResult—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);
  }
});

IfElseMainSuccess

event details

Emitted when the main call in if_else succeeded.

When it fires

  • if_else call executed
  • Main call succeeded
Emitted by: if_else
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);
  }
});

IfElseFallbackCalled

event details

Emitted when the main call failed and fallback was executed.

When it fires

  • if_else executed
  • Main failed

Fields

NameTypeFormatDescription
main_errorDispatchErrorDispatch ErrorError from the main call that triggered fallback
Emitted by: if_else
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

batched_calls_limit

constant details

Maximum number of calls that can be batched in a single transaction.

Type: u32
Value: 10922
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 batched_calls_limit constant
const value = await api.constants.Utility.batched_calls_limit();
console.log("batched_calls_limit:", value);

Errors 3

TooManyCalls

error details #0

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

InvalidDerivedAccount

error details #1

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

SafeDerivationFailed

error details #2

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