Optimism

Optimism

eth_call

eth_call executes a message call locally against the EVM without writing to the chain or spending gas. Use it for every read operation you can't satisfy with a balance / nonce / storage lookup — anything that requires running EVM bytecode.

When to reach for it

  • Read ERC-20 / ERC-721 / ERC-1155 state (balanceOf, ownerOf, tokenURI, decimals, symbol).
  • Query DEX pools for prices or reserves.
  • Simulate the outcome of a transaction before submitting it.
  • Probe contract behaviour with arbitrary state overrides (see below).

Parameters

eth_call takes a transaction object + a block reference:

FieldTypeDescription
fromstring(optional) sender address — set when the contract reads msg.sender.
tostring(required) target contract address.
gasstring(optional) gas limit in hex. Mostly irrelevant since the call doesn't spend gas.
gasPricestring(optional) gas price in hex. Same caveat.
valuestring(optional) wei sent with the call.
datastring(required) ABI-encoded calldata: 4-byte function selector + packed arguments.

The second argument is a block tag (latest, safe, finalized, etc.) or hex block number.

eth_call also accepts an optional state override as a third argument — a map from address to fake balance / nonce / code / storage. Useful for "what-if" simulations.

Response shape

The result is the raw return data of the executed function — a hex string you decode with the contract's ABI.

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

Decoded as uint256, that's 25,000,000,000,000,000,000,000 — 25,000 with 18 decimals.

Quick recipes

ERC-20 selectors (call-data prefixes) you'll see most often:

MethodSelector
balanceOf(address)0x70a08231
decimals()0x313ce567
symbol()0x95d89b41
totalSupply()0x18160ddd
allowance(address,address)0xdd62ed3e

Append the 32-byte padded argument(s) to the selector to build the data field.

Pitfalls

  1. State at latest may differ from state at submission time. If you're using eth_call to validate transaction parameters, expect transient drift; re-validate on-chain.
  2. State overrides are not portable. Not every provider supports the third argument — TheRPC does, but if your code might run against a different upstream, fall back to a pure eth_call.
  3. Reverts surface as errors. A failed eth_call returns error.code = 3 with revert data attached — decode it the same way you decode revert reasons from eth_sendRawTransaction.

See also

Parameters

JSON object: { from?, to, gas?, gasPrice?, value?, data }

block number, hash, "latest", "pending", "earliest" or "safe"

curl https://optimism.therpc.io \
-X POST \
-H 'Content-Type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599","data":"0x70a082310000000000000000000000006E0d01A76C3Cf4288372a29124A26D4353EE51BE"},"latest"]}'

Ready to call this in production?

Free tier covers personal projects. Pay-as-you-go scales without a card.