This is one of the most commonly used API calls. It is used to read from the blockchain which includes executing smart contracts but does not publish anything to the blockchain. This call does not consume any Ether.
Starting from Geth 1.9.13,
eth_call
will check the balance of the sender (to make sure that the sender has enough gas to complete the request) before executing the call, when one of the following conditions is true:
a) thegas_price
parameter is populated, or
b) the contract function being called (i.e. indata
modifies blockchain state)In these two cases, even though the
eth_call
requests don't consume any gas, thefrom
address must have enough gas to execute the call as if it were a write transaction becauseeth_call
is being used to simulate the transaction.
Parameters
OBJECT
- The transaction call object
Key | Required | Type | Detail |
---|---|---|---|
from | ❌ | String | Address the transaction is sent from. |
to | ✅ | String | Address the transaction is directed to. |
gas | ❌ | String | A hex code of an integer that represents the gas provided for the transaction execution. |
gasPrice | ❌ | String | A hex code of an integer that represents the price used for each paid gas. |
value | ❌ | String | A hex code of an integer that represents the value sent with this transaction. |
data | ❌ | String | Hash of method signature and encoded parameters. Learn more here. |
- `BLOCK PARAMETER
Object Name | Required | Type | Detail |
---|---|---|---|
BLOCK PARAMETER | ✅ | String/Object | A hex code of an integer that represents the block number, "latest", "earliest" , "pending" , or the hash of a block. The hash of a block is an object specified as: {"blockHash": "\<hash_value>"} . Learn more here. |
NOTE:
eth_call
has a timeout restriction at the node level. Batching multipleeth_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.
"params": [
{
"from": "0xb60e8dd61c5d32be8058bb8eb970870f07233155",
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x76c0",
"gasPrice": "0x9184e72a000",
"value": "0x9184e72a",
"data": "0xd46e8dd67c5d32be8d46e8dd67c5d32be8058bb8eb970870f072445675058bb8eb970870f072445675"
},
"latest"
]
Result
The return value of the executed contract method.
Example
Request
curl <your-endpoint> \
-X POST \
-H "Content-Type: application/json" \
-d '{"method":"eth_call","params":[{"from":null,"to":"0x6b175474e89094c44da98b954eedeac495271d0f","data":"0x70a082310000000000000000000000006E0d01A76C3Cf4288372a29124A26D4353EE51BE"}, "latest"],"id":1,"jsonrpc":"2.0"}'
Return
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x"
}