call

Call v334 → current #6

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

View calls on chain

Click items to navigate. Pan and zoom to explore.

Used by: developers

The Big Picture

This is the primary way to interact with deployed WASM smart contracts. The contract receives your call data, executes its logic, and returns a result. Contracts can store state, emit events, transfer value, and call other contracts. Gas limits protect the network from infinite loops.

Why This Matters

Smart contracts extend the blockchain with custom logic. This call lets you invoke that logic - whether it's a token transfer, a swap, a governance vote, or any other programmed behavior.

Example Scenario

You want to transfer tokens in an ERC20-style contract. You call Contracts.call with dest=contract_address, value=0, gas_limit=100000, data=encoded_transfer(recipient, amount). The contract executes, emits Transfer event, updates balances in its storage. Called event confirms execution.

Common Questions

What's the 'data' parameter?
SCALE-encoded call data for the contract. Typically includes a selector (function ID) and arguments. Use the contract's ABI/metadata to encode correctly.
How do I set gas_limit?
Estimate using dry-run calls (contracts_call RPC) or use generous limits. Unused gas is refunded. Too low = OutOfGas error; too high = just wastes the estimation effort.
What if the contract reverts?
The transaction still succeeds (you pay gas), but state changes are rolled back. Check the dispatch result for contract-level errors.

Use Cases

  • Execute smart contract functions
  • Read contract state through view functions
  • Interact with DeFi protocols built on contracts
  • Trigger contract-based automation

From Chain Metadata

Makes a call to an account, optionally transferring some balance.

Input Parameters

#NameTypeDescription
0
dest
MultiAddress AccountIdLookupOf<T>dest: Account address as a lookup source (typically resolves to AccountId)
1
value
Compact<u64> Cpt BalanceOf<T>value: Balance in chain native currency (RAO for TAO; ÷10⁹) (RAO -> TAO (/ 10^9))
2
gas_limit
Weight gas_limit: Substrate dispatch weight (computational cost)
3
storage_deposit_limit
Option Option<<BalanceOf<T> as codec::HasCompact>::Type>storage_deposit_limit (Option)
4
data
Vec<u8> Vec data (Vec<u8>)

Permissions

Origin
Unknown
Required Role

Permission data inferred from metadata. May be incomplete.

Requirements

  • Contract exists at the destination address
  • Caller has sufficient balance for value transfer and gas
  • Gas limit is sufficient for contract execution
  • Contract code is valid and not corrupted

Effects

Storage Modified

Postconditions

  • Contract code executed
  • Called event emitted
  • State changes from contract persisted (if successful)
  • Gas consumed deducted from caller

Side Effects

  • Contract may emit custom events (ContractEmitted)
  • Contract may modify its storage
  • Contract may call other contracts (delegate calls)
  • Contract may transfer value to other accounts
  • Storage deposits may be charged for state growth

Code Examples

// ----------------------------------------------------------------------
// 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 call (typed, named args)
const dest = undefined as any /* MultiAddress — replace with real value */;
const value = 0n;
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,
});

Runtime Info

Pallet Index
29
Call Index
6
First Version
v334
Current Version
v411