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 dest (MultiAddress)
1
value
Compact<u64> CptValue in RAO (÷10⁹ for TAO) (RAO -> TAO (/ 10^9))
2
gas_limit
Weight gas_limit (Weight)
3
storage_deposit_limit
Option storage_deposit_limit (Option)
4
data
Vec<u8> Vecdata (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

import { ApiPromise, WsProvider } from "@polkadot/api";
import { stringCamelCase } from "@polkadot/util";

const provider = new WsProvider("wss://entrypoint-finney.opentensor.ai:443");
const api = await ApiPromise.create({ provider });

// Build call call
const dest = 0 as any /* MultiAddress */;
const value = 0;
const gas_limit = 0 as any /* Weight */;
const storage_deposit_limit = 0 as any /* Option */;
const data = 0;

const call = api.tx[stringCamelCase("Contracts")][stringCamelCase("call")](
  dest,
  value,
  gas_limit,
  storage_deposit_limit,
  data
);

Runtime Info

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