eth_call
Executes a new message call immediately without creating a transaction on MegaETH. Used for reading smart contract state.
Why MegaETH? Build on the first real-time blockchain with sub-millisecond latency and 100,000+ TPS with sub-millisecond transaction streaming with 100,000+ sustained TPS and full EVM compatibility.
Use Cases#
The eth_call method is essential for:
- Reading contract state - Query view/pure functions
- Simulating transactions - Test execution without gas costs
- DeFi integrations - Check prices, balances, allowances for high-frequency trading, real-time gaming, instant payments, and latency-sensitive applications
- Complex queries - Execute multi-step contract logic
Gas Limit Restriction#
Gas Limit on MegaETH
On MegaETH, eth_call requests are subject to a maximum gas limit of 10,000,000. This limit ensures optimal real-time performance across the network.
If your contract call requires more gas, consider:
- Breaking the operation into smaller calls
- Optimizing your smart contract logic
- Using view functions that return aggregated data
Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
from | DATA | No | 20-byte address executing the call |
to | DATA | Yes | 20-byte contract address |
gas | QUANTITY | No | Gas limit for the call |
gasPrice | QUANTITY | No | Gas price in wei |
value | QUANTITY | No | Value to send in wei |
data | DATA | Yes | Encoded function call data |
blockParameter | QUANTITY|TAG | Yes | Block number or tag |
Request#
{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0x1F006CCc9Ac133035D8B9bb17E5739E6a17E8C51",
"data": "0x06fdde03"
},
"latest"
],
"id": 1
}
Returns#
| Type | Description |
|---|---|
DATA | The return value of the executed contract function |
Response#
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"
}
Code Examples#
- cURL
- JavaScript
- Python
# Call ERC20 name() function
curl -X POST https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [{
"to": "0x1F006CCc9Ac133035D8B9bb17E5739E6a17E8C51",
"data": "0x06fdde03"
}, "latest"],
"id": 1
}'
import { JsonRpcProvider, Contract } from 'ethers';
const provider = new JsonRpcProvider('https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY');
// ERC20 ABI for common read functions
const ERC20_ABI = [
"function name() view returns (string)",
"function symbol() view returns (string)",
"function decimals() view returns (uint8)",
"function totalSupply() view returns (uint256)",
"function balanceOf(address owner) view returns (uint256)"
];
// Read token information
const tokenAddress = '0x1F006CCc9Ac133035D8B9bb17E5739E6a17E8C51';
const contract = new Contract(tokenAddress, ERC20_ABI, provider);
// Get token name
const name = await contract.name();
console.log('Token name:', name);
// Get token symbol and decimals
const symbol = await contract.symbol();
const decimals = await contract.decimals();
console.log(`Token: ${symbol}, Decimals: ${decimals}`);
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api-megaeth-mainnet.n.dwellir.com/YOUR_API_KEY'))
# ERC20 token ABI for common functions
ERC20_ABI = [
{
"constant": True,
"inputs": [],
"name": "name",
"outputs": [{"name": "", "type": "string"}],
"type": "function"
},
{
"constant": True,
"inputs": [],
"name": "symbol",
"outputs": [{"name": "", "type": "string"}],
"type": "function"
},
{
"constant": True,
"inputs": [],
"name": "decimals",
"outputs": [{"name": "", "type": "uint8"}],
"type": "function"
}
]
# Create contract instance
token_address = '0x1F006CCc9Ac133035D8B9bb17E5739E6a17E8C51'
contract = w3.eth.contract(address=token_address, abi=ERC20_ABI)
# Call name() function
name = contract.functions.name().call()
print(f'Token name: {name}')
# Get additional token info
symbol = contract.functions.symbol().call()
decimals = contract.functions.decimals().call()
print(f'Token: {symbol}, Decimals: {decimals}')
Error Handling#
| Error Code | Message | Description |
|---|---|---|
| -32000 | Execution reverted | Contract function reverted |
| -32602 | Invalid parameters | Invalid data encoding |
| -32015 | VM execution error | Contract logic error |
Related Methods#
eth_estimateGas- Estimate gas for transactioneth_sendRawTransaction- Send actual transaction