set_key

Call v101 → current #2

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

View calls on chain

Click items to navigate. Pan and zoom to explore.

Used by: validatorssubnet ownersdevelopers

The Big Picture

Administrative control of a Substrate network is critical. set_key allows the current administrator to transfer that control to someone else. This is commonly used during network transitions - for example, moving from a single developer key to a multisig controlled by multiple parties.

Why This Matters

Networks evolve, and so should their governance. Initially, a single developer might hold the sudo key. As the network matures, control should transfer to a more decentralized entity - a council multisig, for example.

Example Scenario

Your network launched with your development key as sudo. Now it's time to decentralize. You call set_key(new=multisig_address). KeyChanged event confirms the transfer. Your old key no longer has sudo access; the multisig does.

Common Questions

Can I transfer to any account?
Yes, including multisig accounts, which is recommended for production networks. Ensure you control the new key before transferring!
Is this reversible?
Only if the new key holder agrees to transfer back. Once set, only the new key can call set_key to change it again.

Use Cases

  • Transfer administrative control to new entity
  • Rotate sudo key for security
  • Migrate from development to governance multisig
  • Emergency key rotation if compromise suspected

From Chain Metadata

Authenticates the current sudo key and sets the given AccountId (`new`) as the new sudo key. The dispatch origin for this call must be _Signed_. ## Complexity O(1).

Input Parameters

#NameTypeDescription
0
new
MultiAddress new (MultiAddress)

Permissions

Origin
Root
Required Role

Requirements

  • Signer must be the current sudo key
  • New key must be a valid account

Effects

Events Emitted

Storage Modified

Postconditions

  • Sudo.Key storage updated to new account
  • Old sudo key loses administrative access
  • KeyChanged event emitted

Side Effects

  • Previous sudo key can no longer execute sudo calls
  • New key immediately gains sudo privileges

Code Examples

import { ApiPromise, WsProvider } from "@polkadot/api";
import { stringCamelCase } from "@polkadot/util";

const provider = new WsProvider("wss://entrypoint-finney.opentensor.ai:443");
const api = await ApiPromise.create({ provider });

// Build set_key call
const new = 0 as any /* MultiAddress */;

const call = api.tx[stringCamelCase("Sudo")][stringCamelCase("set_key")](
  new
);

Runtime Info

Pallet Index
12
Call Index
2
First Version
v101
Current Version
v393