All pallets

Contracts docs

Look up any call, event, or storage item with code examples. Runtime v490 · Block #9,478,217

Developer documentation for the Contracts pallet of the Subtensor blockchain, part of the Bittensor decentralized AI network. This page is designed for developers integrating with the chain: look up any call, event, or storage item, copy code examples in TypeScript, Python, or Rust, and filter by your role. For in-depth explanations, version history, and relationships between items, see the Reference section.

Contracts

Deprecated version if [`Self::call`] for use in an in-storage `Call`.

Index: 29 77 items

Calls 10

call_old_weight

call details

Legacy call interface using old weight format (deprecated).

Parameters

NameTypeFormatDescription
destMultiAddress—dest: Account address as a lookup source (typically resolves to AccountId)
valueCompact<TaoBalance>TaoBalancevalue: Balance in chain native currency (RAO for TAO; ÷10⁹)
gas_limitCompact<u64>Integergas_limit: Legacy Substrate weight (pre-WeightV2)
storage_deposit_limitOption—storage_deposit_limit (Option)
dataVec<u8>Array of Integer (0-255)data (Vec<u8>)
Modifies: ContractInfoOf
// ----------------------------------------------------------------------
// HEADS UP: 2 args below have a complex type with no usable default.
// Look for `undefined as any` and replace them with real values
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
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 call_old_weight call (typed, named args)
const dest = undefined as any /* MultiAddress — replace with real value */;
const value = undefined as any /* TaoBalance — replace with real value */;
const gas_limit = 0n;
const storage_deposit_limit = undefined;
const data = Binary.fromOpaque(new Uint8Array(0));

const tx = api.tx.Contracts.call_old_weight({
  dest,
  value,
  gas_limit,
  storage_deposit_limit,
  data,
});

instantiate_with_code_old_weight

call details

Legacy instantiate_with_code using old weight format (deprecated).

Parameters

NameTypeFormatDescription
valueCompact<TaoBalance>TaoBalancevalue: Balance in chain native currency (RAO for TAO; ÷10⁹)
gas_limitCompact<u64>Integergas_limit: Legacy Substrate weight (pre-WeightV2)
storage_deposit_limitOption—storage_deposit_limit (Option)
codeVec<u8>Array of Integer (0-255)code (Vec<u8>)
dataVec<u8>Array of Integer (0-255)data (Vec<u8>)
saltVec<u8>Array of Integer (0-255)salt (Vec<u8>)
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
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 instantiate_with_code_old_weight call (typed, named args)
const value = undefined as any /* TaoBalance — replace with real value */;
const gas_limit = 0n;
const storage_deposit_limit = undefined;
const code = Binary.fromOpaque(new Uint8Array(0));
const data = Binary.fromOpaque(new Uint8Array(0));
const salt = Binary.fromOpaque(new Uint8Array(0));

const tx = api.tx.Contracts.instantiate_with_code_old_weight({
  value,
  gas_limit,
  storage_deposit_limit,
  code,
  data,
  salt,
});

instantiate_old_weight

call details

Legacy instantiate using old weight format (deprecated).

Parameters

NameTypeFormatDescription
valueCompact<TaoBalance>TaoBalancevalue: Balance in chain native currency (RAO for TAO; ÷10⁹)
gas_limitCompact<u64>Integergas_limit: Legacy Substrate weight (pre-WeightV2)
storage_deposit_limitOption—storage_deposit_limit (Option)
code_hashH256256-bit Hashcode_hash: Contract code hash
dataVec<u8>Array of Integer (0-255)data (Vec<u8>)
saltVec<u8>Array of Integer (0-255)salt (Vec<u8>)
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
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 instantiate_old_weight call (typed, named args)
const value = undefined as any /* TaoBalance — replace with real value */;
const gas_limit = 0n;
const storage_deposit_limit = undefined;
const code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000";
const data = Binary.fromOpaque(new Uint8Array(0));
const salt = Binary.fromOpaque(new Uint8Array(0));

const tx = api.tx.Contracts.instantiate_old_weight({
  value,
  gas_limit,
  storage_deposit_limit,
  code_hash,
  data,
  salt,
});

upload_code

call details

Uploads WASM contract code without instantiating a contract.

Parameters

NameTypeFormatDescription
codeVec<u8>Array of Integer (0-255)code (Vec<u8>)
storage_deposit_limitOption—storage_deposit_limit (Option)
determinismDeterminism—determinism (Determinism)
Emits: CodeStored
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
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 upload_code call (typed, named args)
const code = Binary.fromOpaque(new Uint8Array(0));
const storage_deposit_limit = undefined;
const determinism = undefined as any /* Determinism — replace with real value */;

const tx = api.tx.Contracts.upload_code({
  code,
  storage_deposit_limit,
  determinism,
});

remove_code

call details

Removes previously uploaded contract code if no instances exist.

Parameters

NameTypeFormatDescription
code_hashH256256-bit Hashcode_hash: Contract code hash
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 remove_code call (typed, named args)
const code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000";

const tx = api.tx.Contracts.remove_code({
  code_hash,
});

set_code

call details

Updates the code of an existing contract to a different code hash (admin only).

Parameters

NameTypeFormatDescription
destMultiAddress—dest: Account address as a lookup source (typically resolves to AccountId)
code_hashH256256-bit Hashcode_hash: Contract code hash
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
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 set_code call (typed, named args)
const dest = undefined as any /* MultiAddress — replace with real value */;
const code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000";

const tx = api.tx.Contracts.set_code({
  dest,
  code_hash,
});

call

call details

Calls a deployed WASM smart contract, executing its code with provided data.

Parameters

NameTypeFormatDescription
destMultiAddress—dest: Account address as a lookup source (typically resolves to AccountId)
valueCompact<TaoBalance>TaoBalancevalue: Balance in chain native currency (RAO for TAO; ÷10⁹)
gas_limitWeightExecution Weightgas_limit: Substrate dispatch weight (computational cost)
storage_deposit_limitOption—storage_deposit_limit (Option)
dataVec<u8>Array of Integer (0-255)data (Vec<u8>)
Modifies: ContractInfoOf
// ----------------------------------------------------------------------
// HEADS UP: 3 args below have a complex type with no usable default.
// Look for `undefined as any` and replace them with real values
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
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 call call (typed, named args)
const dest = undefined as any /* MultiAddress — replace with real value */;
const value = undefined as any /* TaoBalance — replace with real value */;
const gas_limit = undefined as any /* Weight — replace with real value */;
const storage_deposit_limit = undefined;
const data = Binary.fromOpaque(new Uint8Array(0));

const tx = api.tx.Contracts.call({
  dest,
  value,
  gas_limit,
  storage_deposit_limit,
  data,
});

instantiate_with_code

call details

Deploys new WASM contract code and instantiates a contract from it in one operation.

Parameters

NameTypeFormatDescription
valueCompact<TaoBalance>TaoBalancevalue: Balance in chain native currency (RAO for TAO; ÷10⁹)
gas_limitWeightExecution Weightgas_limit: Substrate dispatch weight (computational cost)
storage_deposit_limitOption—storage_deposit_limit (Option)
codeVec<u8>Array of Integer (0-255)code (Vec<u8>)
dataVec<u8>Array of Integer (0-255)data (Vec<u8>)
saltVec<u8>Array of Integer (0-255)salt (Vec<u8>)
// ----------------------------------------------------------------------
// HEADS UP: 2 args below have a complex type with no usable default.
// Look for `undefined as any` and replace them with real values
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
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 instantiate_with_code call (typed, named args)
const value = undefined as any /* TaoBalance — replace with real value */;
const gas_limit = undefined as any /* Weight — replace with real value */;
const storage_deposit_limit = undefined;
const code = Binary.fromOpaque(new Uint8Array(0));
const data = Binary.fromOpaque(new Uint8Array(0));
const salt = Binary.fromOpaque(new Uint8Array(0));

const tx = api.tx.Contracts.instantiate_with_code({
  value,
  gas_limit,
  storage_deposit_limit,
  code,
  data,
  salt,
});

instantiate

call details

Creates a new contract instance from previously uploaded code.

Parameters

NameTypeFormatDescription
valueCompact<TaoBalance>TaoBalancevalue: Balance in chain native currency (RAO for TAO; ÷10⁹)
gas_limitWeightExecution Weightgas_limit: Substrate dispatch weight (computational cost)
storage_deposit_limitOption—storage_deposit_limit (Option)
code_hashH256256-bit Hashcode_hash: Contract code hash
dataVec<u8>Array of Integer (0-255)data (Vec<u8>)
saltVec<u8>Array of Integer (0-255)salt (Vec<u8>)
// ----------------------------------------------------------------------
// HEADS UP: 2 args below have a complex type with no usable default.
// Look for `undefined as any` and replace them with real values
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
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 instantiate call (typed, named args)
const value = undefined as any /* TaoBalance — replace with real value */;
const gas_limit = undefined as any /* Weight — replace with real value */;
const storage_deposit_limit = undefined;
const code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000";
const data = Binary.fromOpaque(new Uint8Array(0));
const salt = Binary.fromOpaque(new Uint8Array(0));

const tx = api.tx.Contracts.instantiate({
  value,
  gas_limit,
  storage_deposit_limit,
  code_hash,
  data,
  salt,
});

migrate

call details

Runs migration logic for contracts after a runtime upgrade.

Parameters

NameTypeFormatDescription
weight_limitWeightExecution Weightweight_limit: Substrate dispatch weight (computational cost)
// ----------------------------------------------------------------------
// HEADS UP: 1 arg below has a complex type with no usable default.
// Look for `undefined as any` and replace it with real value
// before running — the snippet compiles, but will fail at runtime as-is.
// ----------------------------------------------------------------------
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 migrate call (typed, named args)
const weight_limit = undefined as any /* Weight — replace with real value */;

const tx = api.tx.Contracts.migrate({
  weight_limit,
});

Events 10

Instantiated

event details

Emitted when a new smart contract is successfully deployed and instantiated.

When it fires

  • Valid WASM code provided or code_hash exists in PristineCode
  • Caller has sufficient balance for storage deposits
  • Constructor execution succeeded

Fields

NameTypeFormatDescription
deployerAccountIdSS58 AddressAccount that deployed the contract and paid deposits
contractAccountIdSS58 AddressThe deployed contract's unique address
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 Instantiated events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.Contracts.Instantiated.get(block.hash);
  for (const evt of events) {
    console.log("Instantiated:", evt.payload);
  }
});

Terminated

event details

Emitted when a contract is terminated and removed from the chain.

When it fires

  • Contract exists
  • Termination triggered

Fields

NameTypeFormatDescription
contractAccountIdSS58 AddressThe terminated contract's address
beneficiaryAccountIdSS58 AddressAccount receiving remaining contract balance
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 Terminated events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.Contracts.Terminated.get(block.hash);
  for (const evt of events) {
    console.log("Terminated:", evt.payload);
  }
});

CodeStored

event details

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

When it fires

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

Fields

NameTypeFormatDescription
code_hashH256256-bit HashHash uniquely identifying the uploaded WASM code
deposit_heldTaoBalance—Amount of deposit locked for code storage (RAO)
uploaderAccountIdSS58 AddressAccount that uploaded the code
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);
  }
});

ContractEmitted

event details

Emitted when a contract emits a custom event during execution.

When it fires

  • Contract is executing
  • Contract calls seal_deposit_event

Fields

NameTypeFormatDescription
contractAccountIdSS58 AddressContract that emitted this custom event
dataVec<u8>Array of Integer (0-255)Contract-defined event data (decode with contract ABI)
Emitted by: call/ call_old_weight
Modifies: ContractInfoOf
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 ContractEmitted events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.Contracts.ContractEmitted.get(block.hash);
  for (const evt of events) {
    console.log("ContractEmitted:", evt.payload);
  }
});

CodeRemoved

event details

Emitted when contract code is removed from on-chain storage.

When it fires

  • Code exists
  • No contract instances reference this code
  • Caller is original uploader

Fields

NameTypeFormatDescription
code_hashH256256-bit HashHash of the removed code
deposit_releasedTaoBalance—Amount of deposit refunded (RAO)
removerAccountIdSS58 AddressAccount that removed the code (original uploader)
Emitted by: remove_code
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 CodeRemoved events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.Contracts.CodeRemoved.get(block.hash);
  for (const evt of events) {
    console.log("CodeRemoved:", evt.payload);
  }
});

ContractCodeUpdated

event details

Emitted when a contract's code is updated to a different code hash.

When it fires

  • Contract exists
  • Caller has root privileges
  • New code exists

Fields

NameTypeFormatDescription
contractAccountIdSS58 AddressContract whose code was upgraded
new_code_hashH256256-bit HashHash of the new code now running
old_code_hashH256256-bit HashHash of the previous code (before upgrade)
Emitted by: set_code
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);
  }
});

Called

event details

Emitted when a smart contract is called and executed.

When it fires

  • Contract exists
  • Caller provided sufficient gas

Fields

NameTypeFormatDescription
callerOrigin—Account that initiated the contract call
contractAccountIdSS58 AddressContract that was called
Emitted by: call/ call_old_weight
Modifies: ContractInfoOf
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 Called events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.Contracts.Called.get(block.hash);
  for (const evt of events) {
    console.log("Called:", evt.payload);
  }
});

DelegateCalled

event details

Emitted when a contract executes code from another contract in its own context.

When it fires

  • Calling contract exists
  • Target code exists

Fields

NameTypeFormatDescription
contractAccountIdSS58 AddressContract executing the delegate call
code_hashH256256-bit HashCode being executed via delegation
Emitted by: call/ call_old_weight
Modifies: ContractInfoOf
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 DelegateCalled events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.Contracts.DelegateCalled.get(block.hash);
  for (const evt of events) {
    console.log("DelegateCalled:", evt.payload);
  }
});

StorageDepositTransferredAndHeld

event details

Emitted when storage deposit is transferred and held by the contract system.

When it fires

  • Contract operation increased storage
  • Payer has sufficient balance

Fields

NameTypeFormatDescription
fromAccountIdSS58 AddressAccount paying the storage deposit
toAccountIdSS58 AddressContract or system receiving the deposit
amountTaoBalance—Deposit amount transferred (RAO)
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 StorageDepositTransferredAndHeld events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.Contracts.StorageDepositTransferredAndHeld.get(block.hash);
  for (const evt of events) {
    console.log("StorageDepositTransferredAndHeld:", evt.payload);
  }
});

StorageDepositTransferredAndReleased

event details

Emitted when a storage deposit is refunded due to storage cleanup.

When it fires

  • Contract operation decreased storage
  • Deposit was held

Fields

NameTypeFormatDescription
fromAccountIdSS58 AddressContract or system releasing the deposit
toAccountIdSS58 AddressAccount receiving the refund
amountTaoBalance—Deposit amount refunded (RAO)
Emitted by: call
Modifies: ContractInfoOf
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 StorageDepositTransferredAndReleased events
client.finalizedBlock$.subscribe(async (block) => {
  const events = await api.event.Contracts.StorageDepositTransferredAndReleased.get(block.hash);
  for (const evt of events) {
    console.log("StorageDepositTransferredAndReleased:", evt.payload);
  }
});

Storage 7

CodeInfoOf

storage details

Metadata about stored contract code.

Modifier: Optional Keys: 1 Returns: CodeInfo

Keys

NameTypeFormatDescription
key1H256256-bit Hash—
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);

// Query CodeInfoOf storage
const key1 = "0x0000000000000000000000000000000000000000000000000000000000000000";

const result = await api.query.Contracts.CodeInfoOf.getValue(key1);
console.log("CodeInfoOf:", result);

ContractInfoOf

storage details

Information about deployed contract instances.

Modifier: Optional Keys: 1 Returns: ContractInfo

Keys

NameTypeFormatDescription
key1AccountIdSS58 Address—
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);

// Query ContractInfoOf storage
const key1 = "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY";

const result = await api.query.Contracts.ContractInfoOf.getValue(key1);
console.log("ContractInfoOf:", result);

DeletionQueue

storage details

Queue of contracts marked for deletion.

Modifier: Optional Keys: 1 Returns: BoundedVec

Keys

NameTypeFormatDescription
key1u32Integer—
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);

// Query DeletionQueue storage
const key1 = 0;

const result = await api.query.Contracts.DeletionQueue.getValue(key1);
console.log("DeletionQueue:", result);

DeletionQueueCounter

storage details

Counter for the deletion queue.

Modifier: Default Keys: 0 Returns: DeletionQueueManager
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);

// Query DeletionQueueCounter storage (no keys - plain value)
const result = await api.query.Contracts.DeletionQueueCounter.getValue();
console.log("DeletionQueueCounter:", result);

MigrationInProgress

storage details

Cursor tracking migration progress after runtime upgrades.

Modifier: Optional Keys: 0 Returns: BoundedVec
Modified by: migrate
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);

// Query MigrationInProgress storage (no keys - plain value)
const result = await api.query.Contracts.MigrationInProgress.getValue();
console.log("MigrationInProgress:", result);

Nonce

storage details

A running counter used for contract address derivation.

Modifier: Default Keys: 0 Returns: u64 (Integer)
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);

// Query Nonce storage (no keys - plain value)
const result = await api.query.Contracts.Nonce.getValue();
console.log("Nonce:", result);

PristineCode

storage details

Stored WASM code identified by code hash.

Modifier: Optional Keys: 1 Returns: BoundedVec

Keys

NameTypeFormatDescription
key1H256256-bit Hash—
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);

// Query PristineCode storage
const key1 = "0x0000000000000000000000000000000000000000000000000000000000000000";

const result = await api.query.Contracts.PristineCode.getValue(key1);
console.log("PristineCode:", result);

Constants 13

ApiVersion

constant details

API version of the contracts pallet.

Type: ApiVersion
Value: 4
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);

// Query ApiVersion constant
const value = await api.constants.Contracts.ApiVersion();
console.log("ApiVersion:", value);

CodeHashLockupDepositPercent

constant details

Percentage of code deposit locked during instance lifetime.

Type: Perbill
Value: 300000000
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);

// Query CodeHashLockupDepositPercent constant
const value = await api.constants.Contracts.CodeHashLockupDepositPercent();
console.log("CodeHashLockupDepositPercent:", value);

DefaultDepositLimit

constant details

Default maximum deposit for a contract deployment.

Type: TaoBalance
Value: "31534080"
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);

// Query DefaultDepositLimit constant
const value = await api.constants.Contracts.DefaultDepositLimit();
console.log("DefaultDepositLimit:", value);
// Balance: divide by 10^9 for TAO
const tao = value / 1_000_000_000n;

DepositPerByte

constant details

Storage deposit per byte of code or contract storage.

Type: TaoBalance
Value: "30"
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);

// Query DepositPerByte constant
const value = await api.constants.Contracts.DepositPerByte();
console.log("DepositPerByte:", value);
// Balance: divide by 10^9 for TAO
const tao = value / 1_000_000_000n;

DepositPerItem

constant details

Deposit per storage item (key) in a contract.

Type: TaoBalance
Value: "75"
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);

// Query DepositPerItem constant
const value = await api.constants.Contracts.DepositPerItem();
console.log("DepositPerItem:", value);
// Balance: divide by 10^9 for TAO
const tao = value / 1_000_000_000n;

Environment

constant details

Environment constants available to contracts at runtime.

Type: Environment
Value (hex): 0x
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);

// Query Environment constant
const value = await api.constants.Contracts.Environment();
console.log("Environment:", value);

MaxCodeLen

constant details

Maximum size of WASM code that can be uploaded.

Type: u32
Value: 131072
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);

// Query MaxCodeLen constant
const value = await api.constants.Contracts.MaxCodeLen();
console.log("MaxCodeLen:", value);

MaxDebugBufferLen

constant details

Maximum size of the debug buffer for contract debugging.

Type: u32
Value: 2097152
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);

// Query MaxDebugBufferLen constant
const value = await api.constants.Contracts.MaxDebugBufferLen();
console.log("MaxDebugBufferLen:", value);

MaxDelegateDependencies

constant details

Maximum number of delegate dependencies for a contract.

Type: u32
Value: 32
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);

// Query MaxDelegateDependencies constant
const value = await api.constants.Contracts.MaxDelegateDependencies();
console.log("MaxDelegateDependencies:", value);

MaxStorageKeyLen

constant details

Maximum length of a storage key in a contract.

Type: u32
Value: 128
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);

// Query MaxStorageKeyLen constant
const value = await api.constants.Contracts.MaxStorageKeyLen();
console.log("MaxStorageKeyLen:", value);

MaxTransientStorageSize

constant details

Maximum size of transient storage during contract execution.

Type: u32
Value: 1048576
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);

// Query MaxTransientStorageSize constant
const value = await api.constants.Contracts.MaxTransientStorageSize();
console.log("MaxTransientStorageSize:", value);

Schedule

constant details

Cost schedule for contract operations.

Type: Schedule
Value (hex): 0x04000000100000002000000000400000000000400000008060ea000000000000eb040000
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);

// Query Schedule constant
const value = await api.constants.Contracts.Schedule();
console.log("Schedule:", value);

UnsafeUnstableInterface

constant details

Whether unstable/experimental host functions are available.

Type: bool
Value: false
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);

// Query UnsafeUnstableInterface constant
const value = await api.constants.Contracts.UnsafeUnstableInterface();
console.log("UnsafeUnstableInterface:", value);

Errors 37

InvalidSchedule

error details #0

The cost schedule for contract execution is invalid.

Common Causes

  • Corrupted runtime configuration
  • Invalid Schedule constant in runtime

How to Fix

This is a chain configuration issue,Report to chain maintainers,Wait for runtime fix

InvalidCallFlags

error details #1

The call flags specified for this contract call are invalid.

Common Causes

  • Using unsupported flag combinations
  • Deprecated flags in call data

How to Fix

Review documentation for valid call flags,Update client library to latest version,Remove unsupported flags from call

OutOfGas

error details #2

The contract execution ran out of gas before completing.

Common Causes

  • Gas limit set too low for the operation
  • Contract contains infinite or very long loops
  • Complex computation exceeds gas budget

How to Fix

Increase gas_limit parameter,Use dry-run (contracts_call RPC) to estimate required gas,Optimize contract code for gas efficiency,Split complex operations into multiple calls

OutputBufferTooSmall

error details #3

The output buffer provided is too small for the contract's return data.

Common Causes

  • Contract returns more data than expected
  • Output buffer size not properly configured

How to Fix

Increase output buffer size in call parameters,Check contract ABI for expected return data size

TransferFailed

error details #4

A value transfer within the contract failed.

Common Causes

  • Contract has insufficient balance
  • Transfer would reduce balance below existential deposit
  • Recipient can't receive funds

How to Fix

Ensure contract has sufficient balance for transfer,Check existential deposit requirements,Verify recipient address is valid

MaxCallDepthReached

error details #5

Contract call depth exceeded the maximum allowed nesting level.

Common Causes

  • Too many nested contract-to-contract calls
  • Recursive contract calls without proper limits

How to Fix

Reduce call nesting depth,Refactor contract architecture to flatten call hierarchy,Use state patterns instead of deep call chains

ContractNotFound

error details #6

No contract exists at the specified address.

Common Causes

  • Wrong contract address
  • Contract was terminated
  • Contract never deployed at this address

How to Fix

Verify the contract address is correct,Check if contract was terminated (Terminated event),Query ContractInfoOf to verify contract existence

CodeTooLarge

error details #7

The WASM code exceeds the maximum allowed size.

Common Causes

  • Contract code is too large
  • Unoptimized WASM compilation

How to Fix

Query MaxCodeLen for the size limit,Enable WASM optimization in compiler settings,Split functionality across multiple contracts,Remove unused code paths

CodeNotFound

error details #8

No code exists with the specified code hash.

Common Causes

  • Wrong code_hash
  • Code was removed
  • Code was never uploaded

How to Fix

Verify the code_hash is correct,Upload the code first using upload_code,Check CodeInfoOf for code existence

CodeInfoNotFound

error details #9

No code info could be found at the supplied code hash.

Common Causes

  • Code was never uploaded
  • Code was removed after all contracts using it terminated
  • Incorrect code hash provided

How to Fix

Verify the code hash is correct,Upload the code first with upload_code,Check Contracts.CodeInfoOf storage for the hash

OutOfBounds

error details #10

A memory access in the contract went out of bounds.

Common Causes

  • Bug in contract code accessing invalid memory
  • Buffer overflow in contract logic

How to Fix

Fix the contract code to respect memory boundaries,Use safe memory access patterns,Test contract thoroughly before deployment

DecodingFailed

error details #11

Failed to decode input data for the contract.

Common Causes

  • Call data doesn't match expected format
  • Wrong ABI encoding
  • Mismatched selector

How to Fix

Verify call data is correctly SCALE-encoded,Check selector matches the function you're calling,Use correct ABI/metadata for encoding

ContractTrapped

error details #12

The contract execution trapped (crashed) during execution.

Common Causes

  • Contract panic/abort called
  • Unreachable code reached
  • Assertion failed in contract

How to Fix

Debug contract to find trap cause,Check contract logs (if debug enabled),Test with known-good inputs

ValueTooLarge

error details #13

The value being transferred is too large.

Common Causes

  • Transfer amount exceeds limits
  • Overflow in value calculation

How to Fix

Reduce transfer value,Check for overflow in value calculations

TerminatedWhileReentrant

error details #14

Contract was terminated during a reentrant call.

Common Causes

  • Contract self-destructed while another call was in progress
  • Reentrancy led to unexpected termination

How to Fix

Avoid self-destruction in reentrant contexts,Use reentrancy guards,Restructure contract logic

InputForwarded

error details #15

Input data was forwarded to a nested call unexpectedly.

Common Causes

  • Call flags cause input forwarding when not intended
  • Misuse of call options

How to Fix

Review call flags usage,Don't forward input unless intended

RandomSubjectTooLong

error details #16

The subject provided for random number generation is too long.

Common Causes

  • Subject string exceeds maximum length

How to Fix

Shorten the random subject,Check maximum length in documentation

TooManyTopics

error details #17

Too many topics were provided for an event.

Common Causes

  • Contract event has more topics than allowed

How to Fix

Reduce number of indexed/topic fields in event,Check maximum topics limit

NoChainExtension

error details #18

The contract tried to use a chain extension that doesn't exist.

Common Causes

  • Chain doesn't have the required extension
  • Wrong chain/environment

How to Fix

Verify chain supports required extensions,Deploy to a chain with the needed extension,Remove extension usage from contract

XCMDecodeFailed

error details #19

Failed to decode the XCM program.

Common Causes

  • Malformed XCM message
  • Incompatible XCM version
  • Invalid XCM encoding

How to Fix

Verify XCM message format,Check XCM version compatibility,Use proper XCM encoding tools

DuplicateContract

error details #20

A contract already exists at the target address.

Common Causes

  • Same deployer, code, data, salt combination used twice
  • Trying to redeploy without unique salt

How to Fix

Use a different salt value,Check if contract already exists at target address

TerminatedInConstructor

error details #21

Contract tried to self-destruct in its constructor.

Common Causes

  • Constructor contains termination logic
  • Failed condition triggers termination during init

How to Fix

Remove termination from constructor,Handle initialization failures differently

ReentranceDenied

error details #22

A reentrant call was denied by the contract or runtime.

Common Causes

  • Contract has reentrancy protection
  • Runtime reentrancy guard triggered

How to Fix

Avoid reentrant call patterns,Complete current call before starting new one,Use state patterns instead of callbacks

StateChangeDenied

error details #23

A contract attempted to modify state while in read-only mode.

Common Causes

  • Calling a state-modifying API during a dry-run/simulation
  • View function trying to write state

How to Fix

Use read-only operations in view contexts,Separate read and write operations,Execute state changes in a proper transaction

StorageDepositNotEnoughFunds

error details #24

Insufficient funds for storage deposit.

Common Causes

  • Account doesn't have enough free balance
  • Storage growth requires more deposit than available

How to Fix

Add funds to the account paying for storage,Reduce storage usage,Clean up unused storage first

StorageDepositLimitExhausted

error details #25

The storage deposit limit for this call was exceeded.

Common Causes

  • Storage limit parameter too restrictive
  • Contract needs more storage than allowed

How to Fix

Increase storage_deposit_limit in call,Optimize contract to use less storage,Query DefaultDepositLimit for maximum

CodeInUse

error details #26

Cannot remove code because contract instances still use it.

Common Causes

  • Trying to remove code while contracts are still deployed
  • Some instances not yet terminated

How to Fix

Terminate all contract instances using this code first,Wait for deletion queue to process terminated contracts,Check CodeInfoOf refcount

ContractReverted

error details #27

The contract execution was reverted.

Common Causes

  • Contract returned error/revert
  • Business logic check failed
  • Assert/require failed

How to Fix

Check contract logic for revert conditions,Verify inputs meet contract requirements,Debug to find specific revert reason

CodeRejected

error details #28

The WASM code was rejected during validation.

Common Causes

  • Invalid WASM format
  • Forbidden instructions in code
  • Code doesn't meet validation requirements

How to Fix

Compile with correct target (wasm32-unknown-unknown),Use proper contract toolchain (cargo-contract, etc.),Check for forbidden floating-point operations

Indeterministic

error details #29

The code contains non-deterministic operations.

Common Causes

  • Floating-point arithmetic in code
  • Non-deterministic instructions
  • Host functions not available in deterministic mode

How to Fix

Remove floating-point operations,Use fixed-point math instead,Ensure code is fully deterministic

MigrationInProgress

error details #30

A migration is in progress and contract operations are blocked.

Common Causes

  • Runtime upgraded and migration not complete
  • Contracts pallet storage being migrated

How to Fix

Wait for migration to complete,Call migrate() to advance migration,Check MigrationInProgress storage for status

NoMigrationPerformed

error details #31

No migration was performed (nothing to migrate).

Common Causes

  • Calling migrate when no migration is pending
  • Migration already complete

How to Fix

Check MigrationInProgress - if None, no migration needed,Don't call migrate when not required

MaxDelegateDependenciesReached

error details #32

The contract has reached its maximum number of delegate dependencies.

Common Causes

  • Too many delegate calls locked
  • MaxDelegateDependencies limit reached

How to Fix

Unlock some unused delegate dependencies,Check MaxDelegateDependencies constant for the limit,Refactor to use fewer external code dependencies

DelegateDependencyNotFound

error details #33

The dependency was not found in the contract's delegate dependencies.

Common Causes

  • Trying to unlock a dependency that was never locked
  • Wrong code hash provided to unlock

How to Fix

Verify the code hash is in the contract's dependencies,Only unlock dependencies that were previously locked

DelegateDependencyAlreadyExists

error details #34

The contract already depends on the given delegate dependency.

Common Causes

  • Trying to add a dependency that was already locked
  • Duplicate lock_delegate_dependency call

How to Fix

Check if dependency is already registered,Skip adding if already present

CannotAddSelfAsDelegateDependency

error details #35

A contract cannot add its own code hash as a delegate dependency.

Common Causes

  • Trying to lock your own code as a delegate dependency
  • Circular dependency attempt

How to Fix

Delegate dependencies should reference OTHER code hashes,Remove the self-referential dependency

OutOfTransientStorage

error details #36

Cannot add more data to transient storage.

Common Causes

  • Transient storage limit exceeded
  • Too much data stored in transient storage during execution

How to Fix

Reduce transient storage usage,Check MaxTransientStorageSize constant for the limit,Clear transient storage entries when no longer needed