state_call - Hydration RPC Method
Call a runtime API function on Hydration. Execute on-chain computations like account nonce lookups, fee estimation, and custom runtime logic without submitting a transaction.
Calls a runtime API function on Hydration 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 Hydration? Build on Polkadot's leading DEX with $200M+ TVL, Omnipool AMM, and native HOLLAR stablecoin with Omnipool with reduced slippage, permissioned listings, 3M DOT DAO allocation, and 200%+ APR farm yields.
When to Use This Method
state_call is essential for DeFi developers, liquidity providers, and DAOs requiring capital-efficient trading:
- 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 single-sided liquidity provision, cross-chain trading (SOL, KSM, tBTC), and HOLLAR decentralized stablecoin - 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 Hydration. Essential for compatibility checking, upgrade detection, and transaction construction on Polkadot's leading DEX with $200M+ TVL, Omnipool AMM, and native HOLLAR stablecoin.
state_getKeys - JSON-RPC Method
Get storage keys matching a prefix in Hydration via JSON-RPC. Query multiple storage entries efficiently.