state_call - Mythos RPC Method
Call a runtime API function on Mythos. Execute on-chain computations like account nonce lookups, fee estimation, and custom runtime logic without submitting a transaction.
Calls a runtime API function on Mythos and returns the SCALE-encoded result. This method lets you execute runtime logic (such as AccountNonceApi, TransactionPaymentApi, or any custom runtime API) without submitting a transaction.
Why Mythos? Build on the gaming blockchain powering FIFA Rivals and NFL Rivals with World ID verification with World ID proof-of-humanity, Polkadot security, Snowbridge cross-chain bridge, and 1M+ downloads per title.
When to Use This Method
state_call is essential for game studios, player-driven economy builders, and teams requiring verified human-only gameplay:
- Account Nonce Queries -- Retrieve the next nonce for an account via
AccountNonceApi_account_noncebefore constructing extrinsics - Fee Estimation -- Use
TransactionPaymentApi_query_infoto estimate fees for AAA gaming (FIFA Rivals, NFL Rivals, Pudgy Party), player-owned economies, and bot-resistant matchmaking - Custom Runtime APIs -- Call any runtime API exposed by the chain (e.g., staking queries, governance lookups, DeFi calculations)
- Historical State Queries -- Execute runtime logic at a specific block by providing an optional block hash
Code Examples
Common Use Cases
1. Get Account Nonce for Transaction Construction
Query the next nonce before building and signing an extrinsic:
import { ApiPromise, WsProvider } from '@polkadot/api';
async function getNextNonce(api, address) {
// Using the runtime API directly (preferred over system.accountNextIndex)
const nonce = await api.call.accountNonceApi.accountNonce(address);
return nonce.toNumber();
}
async function buildAndSendTransfer(api, sender, recipient, amount) {
const nonce = await getNextNonce(api, sender.address);
const transfer = api.tx.balances.transferKeepAlive(recipient, amount);
const hash = await transfer.signAndSend(sender, { nonce });
console.log(`Sent with nonce ${nonce}, hash: ${hash.toHex()}`);
}2. Custom Runtime API Queries
Call chain-specific runtime APIs for DeFi or governance queries:
async function queryRuntimeApi(api, methodName, encodedArgs, blockHash) {
const params = [methodName, encodedArgs];
if (blockHash) params.push(blockHash);
const result = await api.rpc.state.call(...params);
return result.toHex();
}
// Example: query a staking-related runtime API at a specific block
const stakingResult = await queryRuntimeApi(
api,
'StakingApi_nominations_quota',
'0x00e1f505', // SCALE-encoded balance
'0xabc123...' // specific block hash
);3. Historical State Query
Execute a runtime API call against a historical block:
async function getNonceAtBlock(api, address, blockHash) {
const nonce = await api.call.accountNonceApi.accountNonce.at(blockHash, address);
return nonce.toNumber();
}
// Compare current nonce vs historical nonce
const currentNonce = await getNonceAtBlock(api, address);
const historicalNonce = await getNonceAtBlock(api, address, oldBlockHash);
console.log(`Transactions since block: ${currentNonce - historicalNonce}`);Error Handling
Common errors and solutions:
| Error Code | Description | Solution |
|---|---|---|
| -32603 | Execution failed | Verify the runtime API method name exists on this chain; check SCALE encoding of input data |
| -32602 | Invalid params | Ensure data is properly SCALE-encoded as a hex string with 0x prefix |
| -32005 | Rate limit exceeded | Reduce request frequency or implement client-side rate limiting |
| Method not found | Runtime API unavailable | The specified runtime API is not implemented by this chain's runtime -- use state_getMetadata to check |
Related Methods
state_getStorage-- Query a single storage item by keystate_getMetadata-- Get full runtime metadata including available runtime APIsstate_queryStorageAt-- Batch query multiple storage keys at a specific blockpayment_queryInfo-- Estimate fees (usesTransactionPaymentApiinternally)system_version-- Get the node version for compatibility checking
state_getRuntimeVersion
Get the runtime version on Mythos. Essential for compatibility checking, upgrade detection, and transaction construction on the gaming blockchain powering FIFA Rivals and NFL Rivals with World ID verification.
state_getKeys (Mythos)
Enumerate Mythos storage keys for a prefix using state_getKeys.