All pallets

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.

Index: 12 11 items

Calls 5

sudo

call details

Authenticates the sudo key and dispatches a function call with Root origin.

Parameters

NameTypeFormatDescription
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 sudo call (typed, named args)
const call = undefined as any /* RuntimeCall — replace with real value */;

const tx = api.tx.Sudo.sudo({
  call,
});

sudo_unchecked_weight

call details

Dispatches a call with Root origin and custom weight specification.

Parameters

NameTypeFormatDescription
callRuntimeCall—call (RuntimeCall)
weightWeightExecution Weightweight: Substrate dispatch weight (computational cost)
Emits: Sudid
// ----------------------------------------------------------------------
// 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,
});

set_key

call details

Authenticates the current sudo key and sets a new sudo key.

Parameters

NameTypeFormatDescription
newMultiAddress—new: Account address as a lookup source (typically resolves to AccountId)
Emits: KeyChanged
Modifies: Key
// ----------------------------------------------------------------------
// 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_,
});

sudo_as

call details

Dispatches a call with Signed origin from a specified account.

Parameters

NameTypeFormatDescription
whoMultiAddress—who: Account address as a lookup source (typically resolves to AccountId)
callRuntimeCall—call (RuntimeCall)
Emits: SudoAsDone
// ----------------------------------------------------------------------
// 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,
});

remove_key

call details

Permanently removes the sudo key, disabling all sudo functionality.

Emits: KeyRemoved
Modifies: Key
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

Sudid

event details

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

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

KeyChanged

event details

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

NameTypeFormatDescription
old_keyOption—Previous sudo key (None if sudo was just enabled)
new_keyAccountIdSS58 AddressNew sudo key account address
Emitted by: set_key
Modifies: Key
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);
  }
});

KeyRemoved

event details

Emitted when the sudo key is permanently removed, disabling sudo.

When it fires

  • Sudo key holder executed remove_key
  • This is an irreversible action
Emitted by: remove_key
Modifies: Key
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);
  }
});

SudoAsDone

event details

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

NameTypeFormatDescription
sudo_resultResult—Result of the inner call execution (Ok or Err with error details)
Emitted by: sudo_as/ sudo
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

Key

storage details

The AccountId of the current sudo key, if any.

Modifier: Optional Keys: 0 Returns: AccountId (SS58 Address)
Modified by: remove_key/ set_key
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

RequireSudo

error details #0

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