githubEdit

eth_call - Polygon

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

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

Parameter
Type
Required
Description

transaction

object

Yes

Transaction call object

blockParameter

string

Yes

Block number in hex, or "latest", "earliest", "pending", "safe", "finalized"

Transaction Object

Field
Type
Required
Description

from

string

No

The address the transaction is sent from

to

string

Yes

The contract address to call

gas

string

No

Gas limit for the call (hex)

gasPrice

string

No

Gas price in wei (hex)

value

string

No

Value to send in wei (hex)

data

string

No

Encoded function call data

Request

cURL
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": "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
        "data": "0x70a082310000000000000000000000005aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed"
    }, "latest"],
    "id": "getblock.io"
}'

Response

Response Parameters

Field
Type
Description

jsonrpc

string

JSON-RPC version (2.0)

id

string

Request identifier

result

string

The 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

Error Handling

Status Code
Error Message
Cause

403

Forbidden

Missing or invalid ACCESS-TOKEN

-32000

execution reverted

Contract execution failed

-32000

insufficient funds

Simulated transaction requires more value

-32602

Invalid params

Invalid transaction object or block parameter

Web3 Integration

Last updated

Was this helpful?