Executes a new message call immediately without creating a transaction on the block chain.
Parameter
-
Object
- The transaction call objectfrom
: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 gasmaxPriorityFeePerGas
: 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 withgasPrice
.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 withgasPrice
.value
:QUANTITY
- (optional) Integer of the value sent with this transactiondata
: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: -
FIELD TYPE BYTES OPTIONAL DESCRIPTION balance Quantity <32 Yes Fake balance to set for the account before executing the call. nonce Quantity <8 Yes Fake nonce to set for the account before executing the call. code Binary any Yes Fake EVM bytecode to inject into the account before executing the call. state Object any Yes Fake key-value mapping to override all slots in the account storage before executing the call. stateDiff Object any Yes Fake 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://polygon-mainnet-archive.allthatnode.com/8U3JLUhzIDg3GShvy9hkCCSYkLGc11kj \
--request POST \
--header "Content-Type: application/json" \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"from": "0x014e32b21c634259b1a281ceae50ba88979cd084",
"to": "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619",
"gas": "0x13880",
"gasPrice": "0x12D7BD4351",
"data": "0x095ea7b3000000000000000000000000ba12222222228d8ba445958a75a0704d566bf2c800000000000000000000000000000000000000000000000000925f2e84bf0000"
},
"0x2B9ACCD",
{"0x014e32b21c634259b1a281ceae50ba88979cd084":{
"balance": "0x277BFC44534B0000"
}}
]
}
'
Returns
DATA
- the return value of executed contract.
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x0000000000000000000000000000000000000000000000000000000000000001"
}