CodeStored

Event v334 → current #2

Emitted when contract code is uploaded and stored on-chain.

View events on chain
Useful for: developersanalytics

The Big Picture

Before contracts can be instantiated, code must be uploaded. This confirms code is on-chain. The code_hash uniquely identifies the code.

Use Cases

  • Track new code uploads
  • Build code registries
  • Monitor developer activity

From Chain Metadata

Code with the specified hash has been stored.

Triggers

Preconditions

  • Valid WASM code provided
  • Code passes validation
  • Caller has sufficient balance for deposit

Effects

Postconditions

  • Code stored in PristineCode
  • CodeInfoOf populated
  • Storage deposit charged

Side Effects

  • Anyone can now instantiate using this code_hash

Event Data

#NameTypeDescription
0
code_hash
H256 T::HashHash uniquely identifying the uploaded WASM code
1
deposit_held
u64 BalanceOf<T>Amount of deposit locked for code storage (RAO) (RAO -> TAO (/ 10^9))
2
uploader
AccountId Account that uploaded the code (hex -> SS58)

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 CodeStored events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.Contracts.CodeStored.get(block.hash);
  for (const evt of events) {
    console.log("CodeStored:", evt.payload);
  }
});

Runtime Info

Pallet Index
29
Event Index
2
First Version
v334
Current Version
v411