eth_call - Polygon

The eth_call method executes a new message call immediately without creating a transaction on the blockchain. This is the primary method for reading data from smart contracts, including token balances, contract state, and other view/pure functions. The call is executed against the state at the specified block.

Parameters

ParameterTypeRequiredDescription
transactionobjectYesTransaction call object
blockParameterstringYesBlock number in hex, or "latest", "earliest", "pending", "safe", "finalized"

Transaction Object

FieldTypeRequiredDescription
fromstringNoThe address the transaction is sent from
tostringYesThe contract address to call
gasstringNoGas limit for the call (hex)
gasPricestringNoGas price in wei (hex)
valuestringNoValue to send in wei (hex)
datastringNoEncoded function call data

Request

cURL

bashcurl --location --request POST 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_call",
    "params": [{
        "to": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
        "data": "0x70a082310000000000000000000000005aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"
    }, "latest"],
    "id": "getblock.io"
}'

JavaScript (Axios)

javascriptimport axios from 'axios';

const url = 'https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/';

const payload = {
    jsonrpc: '2.0',
    method: 'eth_call',
    params: [{
        to: '0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0',
        data: '0x70a082310000000000000000000000005aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed'
    }, 'latest'],
    id: 'getblock.io'
};

axios.post(url, payload, {
    headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log('Result:', response.data.result))
.catch(error => console.error(error));

Python (requests)

pythonimport requests
import json

url = "https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/"

payload = {
    "jsonrpc": "2.0",
    "method": "eth_call",
    "params": [{
        "to": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
        "data": "0x70a082310000000000000000000000005aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"
    }, "latest"],
    "id": "getblock.io"
}

response = requests.post(url, headers={"Content-Type": "application/json"}, json=payload)
print(response.json())

Rust (reqwest)

rustuse reqwest::header;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = reqwest::Client::new();
    
    let response = client
        .post("https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/")
        .header(header::CONTENT_TYPE, "application/json")
        .body(r#"{
            "jsonrpc": "2.0",
            "method": "eth_call",
            "params": [{
                "to": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
                "data": "0x70a082310000000000000000000000005aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"
            }, "latest"],
            "id": "getblock.io"
        }"#)
        .send()
        .await?;
    
    println!("{}", response.text().await?);
    Ok(())
}

Response

json{
    "jsonrpc": "2.0",
    "id": "getblock.io",
    "result": "0x0000000000000000000000000000000000000000000000056bc75e2d63100000"
}

Response Parameters

FieldTypeDescription
jsonrpcstringJSON-RPC version (2.0)
idstringRequest identifier
resultstringThe return value of the executed contract function (hex-encoded)

Use Case

The eth_call method is essential for:

  • Reading token balances: Query ERC-20/ERC-721 token balances
  • Contract state queries: Read any public/external view or pure function
  • Simulating transactions: Test transaction outcomes before sending
  • Price feeds: Query oracle contracts for current prices
  • DEX quotes: Get swap quotes from decentralized exchanges

Example: Reading ERC-20 Token Balance

JavaScript (ethers)

javascriptimport { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

// ERC-20 balanceOf function selector: 0x70a08231
const tokenAddress = '0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0'; // MATIC token
const walletAddress = '0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed';

// Encode the function call
const iface = new ethers.Interface(['function balanceOf(address) view returns (uint256)']);
const data = iface.encodeFunctionData('balanceOf', [walletAddress]);

const result = await provider.call({
    to: tokenAddress,
    data: data
});

const balance = ethers.getBigInt(result);
console.log('Token Balance:', ethers.formatEther(balance));

Error Handling

Status CodeError MessageCause
403ForbiddenMissing or invalid ACCESS-TOKEN
-32000execution revertedContract execution failed
-32000insufficient fundsSimulated transaction requires more value
-32602Invalid paramsInvalid transaction object or block parameter

Web3 Integration

JavaScript (ethers)

javascriptimport { ethers } from 'ethers';

const provider = new ethers.JsonRpcProvider('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/');

// Direct call
const result = await provider.call({
    to: '0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0',
    data: '0x70a082310000000000000000000000005aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed'
});
console.log('Result:', result);

// Using Contract interface (recommended)
const abi = ['function balanceOf(address) view returns (uint256)'];
const contract = new ethers.Contract('0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0', abi, provider);
const balance = await contract.balanceOf('0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed');
console.log('Balance:', balance.toString());

JavaScript (viem)

javascriptimport { createPublicClient, http, parseAbi } from 'viem';
import { polygon } from 'viem/chains';

const client = createPublicClient({
    chain: polygon,
    transport: http('https://shared.eu-central-1.getblock.io/<ACCESS-TOKEN>/')
});

// Using readContract
const balance = await client.readContract({
    address: '0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0',
    abi: parseAbi(['function balanceOf(address) view returns (uint256)']),
    functionName: 'balanceOf',
    args: ['0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed']
});
console.log('Balance:', balance);