swap_hotkey
Call Re-added v136 → v163, v195 → v274, v276 → v277, v290 → current #70Swaps hotkey to a new address.
View calls on chainCall Workflow
Click items to navigate. Pan and zoom to explore.
The Big Picture
Hotkeys are your public identity on subnets - validators query them, weights target them. swap_hotkey lets you change this identity without losing your UIDs or stake associations. The new hotkey inherits everything from the old one. This is essential for security rotations and infrastructure migrations.
Why This Matters
Your hotkey may be exposed on servers, in configs, or through operational access. Periodically rotating it limits damage from unknown compromises. Swapping preserves your registrations - you don't have to re-register on every subnet.
Example Scenario
Your miner runs on a cloud server with hotkey exposed in config. For security, you want to rotate quarterly. Generate new_hotkey. Call swap_hotkey(old_hotkey, new_hotkey). Your UIDs on subnets 1, 3, and 18 transfer to new_hotkey. Update your miner config, re-serve axon endpoint, continue mining.
Common Questions
- Do I keep my UIDs after swapping?
- Yes - UIDs are preserved. You're changing the key, not the registration. No re-registration needed.
- What about stake from delegators?
- A swap across all subnets moves every delegator to the new hotkey. From v479 a single-subnet swap moves a delegator only when its staking list can take the new hotkey: the list already holds it, the old entry can be renamed, or it has room and the delegator has not set set_reject_staking_hotkey_growth (third parties may grow a list to 128). Otherwise that position stays on the old hotkey and HotkeySwapStakeRetained names it.
- Do I need to re-serve my axon?
- Yes - serve_axon records your endpoint under your hotkey. After swap, serve again with the new hotkey so validators can find you.
- What if someone is using my target hotkey?
- Swap fails. The new hotkey must be completely unused (not registered anywhere). Generate a fresh key to guarantee availability.
Use Cases
- Rotate hotkey for security without losing registrations
- Replace compromised hotkey while preserving UIDs
- Migrate mining operation to new infrastructure
- Key hygiene - periodic rotation as best practice
From Chain Metadata
The extrinsic for user to change its hotkey in subnet or all subnets.
Migration Notes
added field netuid (Option)
Update decoders: SCALE encoding is positional, so any signature change (added, removed, or type-changed fields, or storage shape changes) shifts byte offsets and existing decoders will misparse this item. Re-derive types from the new metadata.
Input Parameters
Permissions
Permission data inferred from metadata. May be incomplete.
Requirements
- Caller owns the hotkey (via coldkey)
- New hotkey not already registered on any subnet
- Swap conditions met
- From v488: when the new hotkey has a HashedAccounts record, the coldkey meets its security floor (HotkeyOwnerPolicyViolation): a hotkey in HashedAccounts.Accounts needs a coldkey with any HashedAccounts record, and a hotkey in HashedAccounts.MlDsaAccounts or HashedAccounts.DerivedAuthorities needs a coldkey in one of those two maps (pallets/subtensor/src/swap/swap_hotkey.rs L215 and staking/helpers.rs L178-L187, runtime/src/hashed_owner.rs L7-L11 at d967d1358, runtime v490)
- From v488, on a swap that moves stake across all subnets or on netuid 0: the queued basket dividend credits of the new and the old hotkey settle or are snapshotted first (BasketDepositPending otherwise; pallets/subtensor/src/swap/swap_hotkey.rs L426-L440 at d967d1358, runtime v490)
Effects
Events Emitted
Storage Modified
Postconditions
- All registrations transferred to new hotkey
- A swap across all subnets moves every staker position to the new hotkey
- From v479, a single-subnet swap moves each staker position unless that staker StakingHotkeys list cannot admit the new hotkey; such a position stays on the old hotkey and HotkeySwapStakeRetained is emitted for it
- UIDs preserved across swap
- From v488 the Services record of the old hotkey moves to the new hotkey on each swapped subnet where the old hotkey is a member, and the DeferredBasket rows keyed by the old hotkey move with its basket (pallets/subtensor/src/swap/swap_hotkey.rs L1082-L1088 and staking/claim_root.rs L1583-L1586 at d967d1358, runtime v490)
- Gamma deposits (from v488) do not move: a GammaDeposits row stays keyed by the old hotkey, and swap/swap_hotkey.rs does not reference GammaDeposits or ColdkeyGammaHotkeys at v490
Side Effects
- Axon/Prometheus endpoints need re-registration
- External systems referencing old hotkey need updating
- From v479 the swapping coldkey own position must be able to follow on a single-subnet swap, or the swap fails with TooManyStakingHotkeys
- From v473, each subnet whose stake moved sets StakeMoveCooldownUntil for the new hotkey to the current block plus HotkeySwapOnSubnetInterval, and a later swap out of that hotkey on that subnet fails with HotKeySwapOnSubnetIntervalNotPassed until then
Code Examples
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 swap_hotkey call (typed, named args)
const hotkey = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
const new_hotkey = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";
const netuid = undefined;
const tx = api.tx.SubtensorModule.swap_hotkey({
hotkey,
new_hotkey,
netuid,
});On-Chain Activity
Infrequent
#78 most used call
50–80% of submissions succeed
As of block 9,385,000
Version History
Runtime Info
View Source- Pallet Index
- 7
- Call Index
- 70
- First Version
- v136
- Current Version
- v490