eth_call | Ethereum
Ethereum API method that enables instant execution of a new message call without requiring the creation of a transaction on the blockchain. This can be useful for testing and debugging by simulating transfers or smart contract transactions and retrieving data from the blockchain.
Get you own node endpoint today
Start for free and get your app to production levels immediately. No credit card required.
You can sign up with your GitHub, X, Google, or Microsoft account.
Disclaimer
The interactive example in this page uses eth_call
to call the poolInfo
method from SushiSwap MasterChef LP staking pool smart contract on Ethereum. It returns the address of the liquidity pool at the index specified in the data, plus other data. In this case, the input is 1, and it returns the current address for the USDC-WETH pool for SushiSwap on Ethereum.
Parameters
-
object
— the transaction call object:from
— (optional) the string of the address used to send the transaction.to
— the string of the address to which the transaction is directed, a wallet, or a smart contract.gas
— (optional) the maximum amount of gas that can be used by the transaction.gasprice
— (optional) the amount of gas price the sender is willing to pay for each gas unit in Wei.value
— (optional) the value sent with this transaction, encoded as hexadecimal.data
— (optional) additional data to be sent with the call, usually used to invoke functions from smart contracts as a string of the hash of the method signature and encoded parameters. See the Ethereum Contract ABI.
-
quantity or tag
— the integer of a block encoded as hexadecimal or the string with:latest
— the most recent block in the blockchain and the current state of the blockchain at the most recent block. A chain reorganization is to be expected.safe
—the block that received justification from the beacon chain. Although this block could be involved in a chain reorganization, it would necessitate either a coordinated attack by the majority of validators or severe propagation latency.finalized
—the block accepted as canonical by more than 2/3 of the validators. A chain reorganization is extremely unlikely, requiring burning at least 1/3 of the staked amount.earliest
— the earliest available or genesis block.pending
—the pending state and transactions block. This is the current state of transactions that have been broadcast to the network but have not yet been included in a block.
See the default block parameter.
Response
data
— the result of executing the specified call on the Ethereum Virtual Machine (EVM), encoded as a hexadecimal string.
eth_call
code examples
Learn more about the ChainstackProvider
in ethers.js
: ethers ChainstackProvider Documentation.
The following code snippets provide a clear demonstration of how to simulate a standard ether transfer between two accounts. Note that when using eth_call
to simulate a transfer or a smart contract transaction, the sender account must have a sufficient balance to cover the associated gas fee.
Executing this code will produce a return value of 0x
, indicating a successful transaction. This implies that the transaction will be executed without any errors when the code is used to send the transaction.
Use case
A common use case for eth_call
is calling smart contract functions. For example, interact with an ERC-20 token smart contract deployed on the Ethereum network and retrieve the balance of a specific account.
The following code uses the web3.js library to call the balanceOf
function of the APE token smart contract on the Ethereum network.
The getAccountBalance
function is called with the address of the account whose balance we want to retrieve. This function creates a new contract instance, calls the balanceOf
function of the smart contract with the provided address, and retrieves the account balance in Wei. The balance is then converted to the ethers unit using the fromWei
function of the web3.utils
object.
Finally, the account balance is printed to the console for easy viewing.