For the complete documentation index, see llms.txt. This page is also available as Markdown.

eth_call - Optimism

Example code for the eth_call json-rpc method. Сomplete guide on how to use eth_call json-rpc in GetBlock.io Web3 documentation.

This method allows you to interact with smart contracts without sending a transaction or spending gas. It's commonly used to read data from contracts, such as checking token balances or calling view functions.

Parameters

Parameter
Type
Description
Required

transaction

Object

Transaction call object with from (optional), to, gas (optional), gasPrice (optional), value (optional), and data fields.

Yes

block

QUANTITY|TAG

Block number in hex, or 'latest', 'earliest', 'pending'.

Yes

Request Sample

curl --location --request POST 'https://go.getblock.io/<ACCESS-TOKEN>/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "jsonrpc": "2.0",
    "method": "eth_call",
    "params": [{"to": "0x4200000000000000000000000000000000000006", "data": "0x70a08231000000000000000000000000742d35Cc6634C0532925a3b844Bc9e7595f7bD5e"}, "latest"],
    "id": "getblock.io"
}'

Response

A successful response returns the following:

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

Response Parameters

  • id: A unique request identifier, matching the id sent in the request body.

  • jsonrpc: Specifies the use of JSON-RPC version 2.0.

  • result: The return value of the executed contract call as a hexadecimal string.

Use Case

The eth_call method is commonly used for:

  • Reading token balances

  • Calling view functions

  • Contract state inspection

  • Simulating transactions

Error handling

Status Code
Error Message
Cause

404

Not found

Missing or invalid ACCESS_TOKEN.

Integration with Web3

The eth_call can help developers to:

  • Enables trustless frontends

  • Reads live contract state without gas

  • Supports dashboards, DeFi analytics, wallets, NFT explorers

  • Let's developers simulate transactions before execution

Last updated

Was this helpful?