Skip to main content

eth_call

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

Why Optimism? Build on the heart of the Superchain powering 60%+ of Ethereum L2 transactions with $6B+ TVL with OP Stack modularity, Superchain interoperability, 17M+ daily transactions across 33 chains, and 20% of tokens for public goods.

Use Cases#

The eth_call method is essential for:

  • Reading contract state - Query view/pure functions
  • Simulating transactions - Test execution without gas costs
  • DeFi integrations - Check prices, balances, allowances for cross-chain DeFi, Superchain-interoperable dApps, and public goods funding recipients
  • Complex queries - Execute multi-step contract logic

Parameters#

ParameterTypeRequiredDescription
fromDATANo20-byte address executing the call
toDATAYes20-byte contract address
gasQUANTITYNoGas limit for the call
gasPriceQUANTITYNoGas price in wei
valueQUANTITYNoValue to send in wei
dataDATAYesEncoded function call data
blockParameterQUANTITY|TAGYesBlock number or tag

Request#

{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"data": "0x70a08231000000000000000000000000d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
},
"latest"
],
"id": 1
}

Returns#

TypeDescription
DATAThe return value of the executed contract function

Response#

{
"jsonrpc": "2.0",
"id": 1,
"result": "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"
}

Code Examples#

# Call ERC20 balanceOf function
curl -X POST https://api-optimism-mainnet-archive.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [{
"to": "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
"data": "0x70a08231000000000000000000000000d8dA6BF26964aF9D7eEd9e03E53415D37aA96045"
}, "latest"],
"id": 1
}'

Error Handling#

Error CodeMessageDescription
-32000Execution revertedContract function reverted
-32602Invalid parametersInvalid data encoding
-32015VM execution errorContract logic error