ContractCodeUpdated
Event v334 → current #5Emitted when a contract's code is updated to a different code hash.
View events on chainUseful for: developersanalytics
The Big Picture
A privileged upgrade mechanism that swaps contract code in-place, preserving address and storage.
Use Cases
- Track contract upgrades
- Monitor governance-approved changes
- Build upgrade history
From Chain Metadata
A contract's code was updated.
Triggers
Emitted by
Preconditions
- Contract exists
- Caller has root privileges
- New code exists
Effects
Storage Modified
Postconditions
- Contract references new code_hash
Side Effects
- Contract behavior changes immediately
Event Data
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);
// Subscribe to ContractCodeUpdated events
client.finalizedBlock$.subscribe(async (block) => {
const events = await api.event.Contracts.ContractCodeUpdated.get(block.hash);
for (const evt of events) {
console.log("ContractCodeUpdated:", evt.payload);
}
});Runtime Info
- Pallet Index
- 29
- Event Index
- 5
- First Version
- v334
- Current Version
- v411