⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

eth_call

Save 80% on eth_call Requests

Alchemy = $11.70 per million eth_call requests
Quicknode = $12.40 per million eth_call requests
Dwellir = $2 per million eth_call requests

Quicknode is 6X more expensive for eth_calls!

Switch to Dwellir today →

Executes a new message call immediately without creating a transaction on the blockchain. Used for reading smart contract state.

When to Use This Method

eth_call is essential for:

  • Reading Contract State - Query view/pure functions
  • Simulating Transactions - Test execution without gas costs
  • DeFi Integrations - Check prices, balances, allowances
  • Complex Queries - Execute multi-step contract logic

Parameters

  1. Transaction Object

    • from - (optional) Address executing the call
    • to - Contract address to call
    • gas - (optional) Gas limit for the call
    • gasPrice - (optional) Gas price in wei
    • value - (optional) Value to send in wei
    • data - Encoded function call data
  2. Block Parameter - QUANTITY|TAG

    • "latest" - Most recent block
    • "pending" - Pending state
    • Block number in hex
{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"data": "0x70a08231000000000000000000000000742d35cc6634c0532925a3b844bc9e7595f0beb"
},
"latest"
],
"id": 1
}

Returns

DATA - The return value of the executed contract function.

Implementation Examples

# Call ERC20 balanceOf function
curl -X POST https://api-ethereum-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [{
"to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"data": "0x70a08231000000000000000000000000d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
}, "latest"],
"id": 1
}'
# Call with from address and gas limit
curl -X POST https://api-ethereum-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [{
"from": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"to": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
"gas": "0x4c4b40",
"data": "0x18160ddd"
}, "latest"],
"id": 1
}'

Common Use Cases

1. DeFi Price Queries

// Uniswap V3 Pool Price Query
async function getPoolPrice(poolAddress) {
const poolABI = [
"function slot0() view returns (uint160 sqrtPriceX96, int24 tick, uint16 observationIndex, uint16 observationCardinality, uint16 observationCardinalityNext, uint8 feeProtocol, bool unlocked)",
"function token0() view returns (address)",
"function token1() view returns (address)"
];

const pool = new Contract(poolAddress, poolABI, provider);

const [slot0, token0, token1] = await Promise.all([
pool.slot0(),
pool.token0(),
pool.token1()
]);

// Calculate price from sqrtPriceX96
const sqrtPriceX96 = slot0.sqrtPriceX96;
const price = (Number(sqrtPriceX96) / (2 ** 96)) ** 2;

return {
token0: token0,
token1: token1,
price: price,
tick: slot0.tick
};
}

2. Multi-Contract Queries

// Batch multiple contract calls
async function multicall(calls) {
const multicallABI = [
"function aggregate(tuple(address target, bytes callData)[] calls) view returns (uint256 blockNumber, bytes[] returnData)"
];

const multicallAddress = "0xcA11bde05977b3631167028862bE2a173976CA11"; // Ethereum Multicall3
const multicall = new Contract(multicallAddress, multicallABI, provider);

const results = await multicall.aggregate(calls);
return results.returnData;
}

3. Access Control Checks

// Check permissions before transaction
async function checkPermissions(contractAddress, userAddress, role) {
const accessControlABI = [
"function hasRole(bytes32 role, address account) view returns (bool)",
"function getRoleAdmin(bytes32 role) view returns (bytes32)"
];

const contract = new Contract(contractAddress, accessControlABI, provider);
const hasRole = await contract.hasRole(role, userAddress);

return hasRole;
}

Error Handling

Error CodeDescriptionSolution
-32000Execution revertedCheck function requirements
-32602Invalid parametersVerify data encoding
-32015VM execution errorCheck contract logic
async function safeCall(to, data) {
try {
const result = await provider.call({ to, data });
return { success: true, data: result };
} catch (error) {
if (error.message.includes('revert')) {
// Try to decode revert reason
const reason = error.data?.replace('0x08c379a0', '');
if (reason) {
const decoded = ethers.utils.toUtf8String('0x' + reason.slice(8));
return { success: false, error: decoded };
}
}
return { success: false, error: error.message };
}
}

Need help? Contact our support team or check the Ethereum documentation.