Sudo docs
Look up any call, event, or storage item with code examples. Runtime v472 · Block #9,197,056
Developer documentation for the Sudo 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.
Sudo
Authenticates the sudo key and dispatches a function call with `Root` origin.
Calls 5
Authenticates the sudo key and dispatches a function call with Root origin.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
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 sudo call (typed, named args)
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Sudo.sudo({
call,
});Dispatches a call with Root origin and custom weight specification.
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 sudo_unchecked_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.Sudo.sudo_unchecked_weight({
call,
weight,
});Authenticates the current sudo key and sets a new sudo key.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
new | MultiAddress | — | new: Account address as a lookup source (typically resolves to AccountId) |
// ----------------------------------------------------------------------
// 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_key call (typed, named args)
const new_ = undefined as any /* MultiAddress — replace with real value */;
const tx = api.tx.Sudo.set_key({
new: new_,
});Dispatches a call with Signed origin from a specified account.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
who | MultiAddress | — | who: Account address as a lookup source (typically resolves to AccountId) |
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 sudo_as call (typed, named args)
const who = undefined as any /* MultiAddress — replace with real value */;
const call = undefined as any /* RuntimeCall — replace with real value */;
const tx = api.tx.Sudo.sudo_as({
who,
call,
});Permanently removes the sudo key, disabling all sudo functionality.
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 remove_key call (no parameters)
const tx = api.tx.Sudo.remove_key();Events 4
Emitted when a sudo call completes, reporting success or failure.
When it fires
- Caller is the current sudo key
- A sudo or sudo_unchecked_weight call was executed
Fields
| Name | Type | Format | Description |
|---|---|---|---|
sudo_result | Result | — | Result of the inner call execution (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 Sudid events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Sudo.Sudid.get(block.hash);
for (const evt of events) {
console.log("Sudid:", evt.payload);
}
});Emitted when the sudo key is changed to a new account.
When it fires
- Previous sudo key executed set_key
- New key is a valid account
Fields
| Name | Type | Format | Description |
|---|---|---|---|
old_key | Option | — | Previous sudo key (None if sudo was just enabled) |
new_key | AccountId | SS58 Address | New sudo key account address |
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 KeyChanged events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Sudo.KeyChanged.get(block.hash);
for (const evt of events) {
console.log("KeyChanged:", evt.payload);
}
});Emitted when the sudo key is permanently removed, disabling sudo.
When it fires
- Sudo key holder executed remove_key
- This is an irreversible action
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 KeyRemoved events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Sudo.KeyRemoved.get(block.hash);
for (const evt of events) {
console.log("KeyRemoved:", evt.payload);
}
});Emitted when a sudo_as call completes, reporting success or failure.
When it fires
- Caller is the current sudo key
- A sudo_as call was executed
- Target account is valid
Fields
| Name | Type | Format | Description |
|---|---|---|---|
sudo_result | Result | — | Result of the inner call execution (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 SudoAsDone events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Sudo.SudoAsDone.get(block.hash);
for (const evt of events) {
console.log("SudoAsDone:", evt.payload);
}
});Storage 1
The AccountId of the current sudo key, if any.
AccountId (SS58 Address)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 Key storage (no keys - plain value)
const result = await api.query.Sudo.Key.getValue();
console.log("Key:", result);Errors 1
The operation requires sudo privileges, but the sender is not the sudo key.
Common Causes
- Calling sudo, sudo_as, set_key, or remove_key from a non-sudo account
- The sudo key was recently changed and you're using the old key
- The sudo key was removed (sudo is disabled)
- Using the wrong wallet/account to sign the transaction
How to Fix
Query Sudo.Key to verify the current sudo account,Ensure you're signing with the correct account (the sudo key),If sudo was removed, the operation is impossible - find alternative governance,Check if the sudo key recently changed and update your configuration