eth_call - Somnia
Example code for the eth_call JSON-RPC method. Complete guide on how to use eth_call JSON-RPC in GetBlock Web3 documentation.
This method executes a new message call immediately without creating a transaction on the blockchain. This is commonly used for reading data from smart contracts, simulating transactions, and querying contract state on the Somnia network.
Parameters
transaction
object
Yes
Transaction call object
blockNumber
string
Yes
Block number in hex, or "latest", "earliest", "pending"
Transaction Object
from
string
No
Sender address
to
string
Yes
Contract address
gas
string
No
Gas limit
gasPrice
string
No
Gas price
value
string
No
Value to send
data
string
No
Encoded function call
Returns
result
string
Return data from the call
Request Example
curl -X POST https://go.getblock.io/<ACCESS-TOKEN>/ \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "getblock.io",
"method": "eth_call",
"params": [
{
"to": "0xContractAddress",
"data": "0x70a08231000000000000000000000000742d35cc6634c0532925a3b844bc9e7595f8bb45"
},
"latest"
]
}'const axios = require('axios');
const url = 'https://go.getblock.io/<ACCESS-TOKEN>/';
const payload = {
jsonrpc: '2.0',
id: 'getblock.io',
method: 'eth_call',
params: [
{
to: '0xContractAddress',
data: '0x70a08231000000000000000000000000742d35cc6634c0532925a3b844bc9e7595f8bb45'
},
'latest'
]
};
axios.post(url, payload, {
headers: { 'Content-Type': 'application/json' }
})
.then(response => console.log(response.data))
.catch(error => console.error(error));Response Example
Response Parameters
result
string
ABI-encoded return value
Use Cases
Read ERC-20 token balances
Query contract state
Simulate transactions before sending
Get NFT metadata
Check allowances and approvals
Error Handling
-32602
Invalid params - malformed call object
-32603
Internal error - execution reverted
-32000
Execution error - contract revert
SDK Integration
Last updated
Was this helpful?