set_code
Call v101 → current #2Set the new runtime code with safety checks (root only).
View calls on chainCall Workflow
This diagram shows the call execution flow: starting with set_code, passing through validation
(signature, nonce, mortality, fee payment), then pre-dispatch checks, followed by dispatch which emits events: CodeUpdated and modifies storage: LastRuntimeUpgrade, and finally post-dispatch where ExtrinsicSuccess is emitted and fees are settled.
Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.
Click items to navigate. Pan and zoom to explore.
Used by: validatorsdevelopers
The Big Picture
This is how Substrate chains upgrade without forking. The runtime is stored on-chain as WASM.
Use Cases
- Deploy runtime upgrades
- Add new features
- Fix bugs
From Chain Metadata
Set the new runtime code. ## Complexity `O(C + S)` where `C` length of `code` and `S` complexity of `can_set_code`
Input Parameters
| # | Name | Type | Description |
|---|---|---|---|
| 0 | code | Vec<u8> Vec | code (Vec<u8>) |
Permissions
Origin
Unknown
Required Role
Requirements
- Caller is root/sudo
- Valid WASM code
- Spec name matches
- Spec version increases
Effects
Events Emitted
Storage Modified
Postconditions
- New runtime code deployed
- CodeUpdated event emitted
Side Effects
- All chain behavior may change
- Nodes need compatible software
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_code call
const code = 0;
const call = api.tx[stringCamelCase("System")][stringCamelCase("set_code")](
code
);Runtime Info
- Pallet Index
- 0
- Call Index
- 2
- First Version
- v101
- Current Version
- v393