eth_call

Executes a new message call immediately without creating a transaction on the block chain.

Parameter

  • Object - The transaction call object

    • from: DATA, 20 Bytes - (optional) The address the transaction is sent from.
    • to: DATA, 20 Bytes - The address the transaction is directed to.
    • gas: QUANTITY - (optional) Integer of the gas provided for the transaction execution. eth_call consumes zero gas, but this parameter may be needed by some executions.
    • gasPrice: QUANTITY - (optional) Integer of the gasPrice used for each paid gas
    • maxPriorityFeePerGas: Maximum fee, in Wei, the sender is willing to pay per gas above the base fee. See EIP-1559 transactions. This can not be use with gasPrice.
    • maxFeePerGas: Maximum total fee (base fee + priority fee), in Wei, the sender is willing to pay per gas. See EIP-1559 transactions. This can not be use with gasPrice.
    • value: QUANTITY - (optional) Integer of the value sent with this transaction
    • data: DATA - (optional) Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI in the Solidity documentation.
  • QUANTITY|TAG - integer block number, or the string "latest", "earliest" or "pending", see the default block parameter

  • Object - State override set

    • The State Override Set option allows you to change the state of a contract before executing the call. This means you can modify the values of variables stored in the contract, such as balances and approvals for that call without actually modifying the contract on the blockchain.ㅤ
      In more technical terms, the state override set is an optional parameter that allows executing the call against a modified chain state. It is an address-to-state mapping, where each entry specifies some state to be overridden prior to executing the call. Each address maps to an object containing:

    • FIELDTYPEBYTESOPTIONALDESCRIPTION
      balanceQuantity<32YesFake balance to set for the account before executing the call.
      nonceQuantity<8YesFake nonce to set for the account before executing the call.
      codeBinaryanyYesFake EVM bytecode to inject into the account before executing the call.
      stateObjectanyYesFake key-value mapping to override all slots in the account storage before executing the call.
      stateDiffObjectanyYesFake key-value mapping to override individual slots in the account storage before executing the call.

      The goal of the state override set is manyfold:

      It can be used by DApps to reduce the amount of contract code needed to be deployed on chain. Code that simply returns internal state or does pre-defined validations can be kept off chain and fed to the node on-demand.

      It can be used for smart contract analysis by extending the code deployed on chain with custom methods and invoking them. This avoids having to download and reconstruct the entire state in a sandbox to run custom code against.

      It can be used to debug smart contracts in an already deployed large suite of contracts by selectively overriding some code or state and seeing how execution changes. Specialized tooling will probably be necessary.

🚧

Note

eth_call has a timeout restriction at the node level. Batching multiple eth_call together on-chain using pre-deployed smart contracts might result in unexpected timeouts that cause none of your calls to complete. Instead, consider serializing these calls, or using smaller batches if they fail with a node error code.

curl https://ethereum-mainnet-archive.allthatnode.com/8U3JLUhzIDg3GShvy9hkCCSYkLGc11kj \
--request POST \
--header "Content-Type: application/json" \
--data '
{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "eth_call",
  "params": [
    {
      "from": "0x4B275BDea1cA622256ebb8B15B51861b52703d16",
      "to": "0xa62894D5196bC44e4C3978400Ad07E7b30352372",
      "gas": "0x13880",
      "gasPrice": "0x4B3ECF6D4",
      "data": "0xa9059cbb0000000000000000000000007422172afc6ea4da9c011e87b7cb002d55b754430000000000000000000000000000000000000000000000000c7d713b0e3f3600"
    },
    "0x10F558C",
    {"0x4B275BDea1cA622256ebb8B15B51861b52703d16":{
      "balance": "0x277BFC44534B0000"
    }}
  ]
}
'

Returns

  • DATA - the return value of executed contract.
{
    "jsonrpc": "2.0",
    "id": 1,
    "result": "0x0000000000000000000000000000000000000000000000000000000000000001"
}

Try Yourself!

Language
Click Try It! to start a request and see the response here!