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`.
Calls 10
Legacy call interface using old weight format (deprecated).
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
dest | MultiAddress | — | dest: Account address as a lookup source (typically resolves to AccountId) |
value | Compact<TaoBalance> | TaoBalance | value: Balance in chain native currency (RAO for TAO; ÷10⁹) |
gas_limit | Compact<u64> | Integer | gas_limit: Legacy Substrate weight (pre-WeightV2) |
storage_deposit_limit | Option | — | storage_deposit_limit (Option) |
data | Vec<u8> | Array of Integer (0-255) | data (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 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,
});Legacy instantiate_with_code using old weight format (deprecated).
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
value | Compact<TaoBalance> | TaoBalance | value: Balance in chain native currency (RAO for TAO; ÷10⁹) |
gas_limit | Compact<u64> | Integer | gas_limit: Legacy Substrate weight (pre-WeightV2) |
storage_deposit_limit | Option | — | storage_deposit_limit (Option) |
code | Vec<u8> | Array of Integer (0-255) | code (Vec<u8>) |
data | Vec<u8> | Array of Integer (0-255) | data (Vec<u8>) |
salt | Vec<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,
});Legacy instantiate using old weight format (deprecated).
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
value | Compact<TaoBalance> | TaoBalance | value: Balance in chain native currency (RAO for TAO; ÷10⁹) |
gas_limit | Compact<u64> | Integer | gas_limit: Legacy Substrate weight (pre-WeightV2) |
storage_deposit_limit | Option | — | storage_deposit_limit (Option) |
code_hash | H256 | 256-bit Hash | code_hash: Contract code hash |
data | Vec<u8> | Array of Integer (0-255) | data (Vec<u8>) |
salt | Vec<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,
});Uploads WASM contract code without instantiating a contract.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
code | Vec<u8> | Array of Integer (0-255) | code (Vec<u8>) |
storage_deposit_limit | Option | — | storage_deposit_limit (Option) |
determinism | Determinism | — | determinism (Determinism) |
// ----------------------------------------------------------------------
// 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,
});Removes previously uploaded contract code if no instances exist.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
code_hash | H256 | 256-bit Hash | code_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,
});Updates the code of an existing contract to a different code hash (admin only).
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
dest | MultiAddress | — | dest: Account address as a lookup source (typically resolves to AccountId) |
code_hash | H256 | 256-bit Hash | code_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,
});Calls a deployed WASM smart contract, executing its code with provided data.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
dest | MultiAddress | — | dest: Account address as a lookup source (typically resolves to AccountId) |
value | Compact<TaoBalance> | TaoBalance | value: Balance in chain native currency (RAO for TAO; ÷10⁹) |
gas_limit | Weight | Execution Weight | gas_limit: Substrate dispatch weight (computational cost) |
storage_deposit_limit | Option | — | storage_deposit_limit (Option) |
data | Vec<u8> | Array of Integer (0-255) | data (Vec<u8>) |
// ----------------------------------------------------------------------
// 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,
});Deploys new WASM contract code and instantiates a contract from it in one operation.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
value | Compact<TaoBalance> | TaoBalance | value: Balance in chain native currency (RAO for TAO; ÷10⁹) |
gas_limit | Weight | Execution Weight | gas_limit: Substrate dispatch weight (computational cost) |
storage_deposit_limit | Option | — | storage_deposit_limit (Option) |
code | Vec<u8> | Array of Integer (0-255) | code (Vec<u8>) |
data | Vec<u8> | Array of Integer (0-255) | data (Vec<u8>) |
salt | Vec<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,
});Creates a new contract instance from previously uploaded code.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
value | Compact<TaoBalance> | TaoBalance | value: Balance in chain native currency (RAO for TAO; ÷10⁹) |
gas_limit | Weight | Execution Weight | gas_limit: Substrate dispatch weight (computational cost) |
storage_deposit_limit | Option | — | storage_deposit_limit (Option) |
code_hash | H256 | 256-bit Hash | code_hash: Contract code hash |
data | Vec<u8> | Array of Integer (0-255) | data (Vec<u8>) |
salt | Vec<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,
});Runs migration logic for contracts after a runtime upgrade.
Parameters
| Name | Type | Format | Description |
|---|---|---|---|
weight_limit | Weight | Execution Weight | weight_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
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
| Name | Type | Format | Description |
|---|---|---|---|
deployer | AccountId | SS58 Address | Account that deployed the contract and paid deposits |
contract | AccountId | SS58 Address | The 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);
}
});Emitted when a contract is terminated and removed from the chain.
When it fires
- Contract exists
- Termination triggered
Fields
| Name | Type | Format | Description |
|---|---|---|---|
contract | AccountId | SS58 Address | The terminated contract's address |
beneficiary | AccountId | SS58 Address | Account 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);
}
});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
| Name | Type | Format | Description |
|---|---|---|---|
code_hash | H256 | 256-bit Hash | Hash uniquely identifying the uploaded WASM code |
deposit_held | TaoBalance | — | Amount of deposit locked for code storage (RAO) |
uploader | AccountId | SS58 Address | Account 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);
}
});Emitted when a contract emits a custom event during execution.
When it fires
- Contract is executing
- Contract calls seal_deposit_event
Fields
| Name | Type | Format | Description |
|---|---|---|---|
contract | AccountId | SS58 Address | Contract that emitted this custom event |
data | Vec<u8> | Array of Integer (0-255) | Contract-defined event data (decode with contract ABI) |
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);
}
});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
| Name | Type | Format | Description |
|---|---|---|---|
code_hash | H256 | 256-bit Hash | Hash of the removed code |
deposit_released | TaoBalance | — | Amount of deposit refunded (RAO) |
remover | AccountId | SS58 Address | Account that removed the code (original uploader) |
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);
}
});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
| Name | Type | Format | Description |
|---|---|---|---|
contract | AccountId | SS58 Address | Contract whose code was upgraded |
new_code_hash | H256 | 256-bit Hash | Hash of the new code now running |
old_code_hash | H256 | 256-bit Hash | Hash of the previous code (before upgrade) |
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);
}
});Emitted when a smart contract is called and executed.
When it fires
- Contract exists
- Caller provided sufficient gas
Fields
| Name | Type | Format | Description |
|---|---|---|---|
caller | Origin | — | Account that initiated the contract call |
contract | AccountId | SS58 Address | Contract that was called |
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);
}
});Emitted when a contract executes code from another contract in its own context.
When it fires
- Calling contract exists
- Target code exists
Fields
| Name | Type | Format | Description |
|---|---|---|---|
contract | AccountId | SS58 Address | Contract executing the delegate call |
code_hash | H256 | 256-bit Hash | Code being executed via delegation |
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);
}
});Emitted when storage deposit is transferred and held by the contract system.
When it fires
- Contract operation increased storage
- Payer has sufficient balance
Fields
| Name | Type | Format | Description |
|---|---|---|---|
from | AccountId | SS58 Address | Account paying the storage deposit |
to | AccountId | SS58 Address | Contract or system receiving the deposit |
amount | TaoBalance | — | 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);
}
});Emitted when a storage deposit is refunded due to storage cleanup.
When it fires
- Contract operation decreased storage
- Deposit was held
Fields
| Name | Type | Format | Description |
|---|---|---|---|
from | AccountId | SS58 Address | Contract or system releasing the deposit |
to | AccountId | SS58 Address | Account receiving the refund |
amount | TaoBalance | — | Deposit amount refunded (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 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
Metadata about stored contract code.
CodeInfo Keys
| Name | Type | Format | Description |
|---|---|---|---|
key1 | H256 | 256-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);Information about deployed contract instances.
ContractInfo Keys
| Name | Type | Format | Description |
|---|---|---|---|
key1 | AccountId | SS58 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);Queue of contracts marked for deletion.
BoundedVec Keys
| Name | Type | Format | Description |
|---|---|---|---|
key1 | u32 | 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 DeletionQueue storage
const key1 = 0;
const result = await api.query.Contracts.DeletionQueue.getValue(key1);
console.log("DeletionQueue:", result);Counter for the deletion queue.
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);Cursor tracking migration progress after runtime upgrades.
BoundedVec 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);A running counter used for contract address derivation.
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);Stored WASM code identified by code hash.
BoundedVec Keys
| Name | Type | Format | Description |
|---|---|---|---|
key1 | H256 | 256-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
API version of the contracts pallet.
ApiVersion4import { 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);Percentage of code deposit locked during instance lifetime.
Perbill300000000import { 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);Default maximum deposit for a contract deployment.
TaoBalance"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;Storage deposit per byte of code or contract storage.
TaoBalance"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;Deposit per storage item (key) in a contract.
TaoBalance"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 constants available to contracts at runtime.
Environment0ximport { 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);Maximum size of WASM code that can be uploaded.
u32131072import { 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);Maximum size of the debug buffer for contract debugging.
u322097152import { 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);Maximum number of delegate dependencies for a contract.
u3232import { 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);Maximum length of a storage key in a contract.
u32128import { 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);Maximum size of transient storage during contract execution.
u321048576import { 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);Cost schedule for contract operations.
Schedule0x04000000100000002000000000400000000000400000008060ea000000000000eb040000import { 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);Whether unstable/experimental host functions are available.
boolfalseimport { 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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