eth_call
Executes a new message call immediately without creating a transaction on zkSync Era. Used for reading smart contract state.
Why zkSync? Build on Matter Labs' flagship zkEVM powering the Elastic Network of interoperable hyperchains with ZK Stack modular framework, hyperchain interoperability, native account abstraction, and $1.9B in tokenized real-world assets.
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 RWA tokenization ($1.9B, 25% market share), hyperchain deployment via ZK Stack, and cross-chain DeFi
- Complex queries - Execute multi-step contract logic
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": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"data": "0x70a08231000000000000000000000000742d35Cc6634C0532925a3b844Bc9e7595f0bEb"
},
"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
- Go
# Call ERC20 balanceOf function
curl -X POST https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"method": "eth_call",
"params": [{
"to": "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
"data": "0x70a08231000000000000000000000000742d35Cc6634C0532925a3b844Bc9e7595f0bEb"
}, "latest"],
"id": 1
}'
import { JsonRpcProvider, Contract } from 'ethers';
const provider = new JsonRpcProvider('https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY');
// ERC20 ABI for common functions
const ERC20_ABI = [
"function balanceOf(address owner) view returns (uint256)",
"function allowance(address owner, address spender) view returns (uint256)",
"function totalSupply() view returns (uint256)",
"function decimals() view returns (uint8)",
"function symbol() view returns (string)"
];
// Read ERC20 token balance
async function getTokenBalance(tokenAddress, walletAddress) {
const contract = new Contract(tokenAddress, ERC20_ABI, provider);
const balance = await contract.balanceOf(walletAddress);
const decimals = await contract.decimals();
const symbol = await contract.symbol();
return {
raw: balance.toString(),
formatted: (Number(balance) / Math.pow(10, decimals)).toFixed(4),
symbol: symbol
};
}
// Direct eth_call
async function directCall(to, data) {
const result = await provider.call({ to, data });
return result;
}
from web3 import Web3
w3 = Web3(Web3.HTTPProvider('https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY'))
def get_erc20_balance(token_address, wallet_address):
# balanceOf(address) selector
function_signature = "balanceOf(address)"
function_selector = w3.keccak(text=function_signature)[:4].hex()
# Encode address parameter
encoded_address = wallet_address[2:].lower().zfill(64)
data = function_selector + encoded_address
# Make the call
result = w3.eth.call({
'to': token_address,
'data': data
})
return int(result.hex(), 16)
balance = get_erc20_balance(
'0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
'0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb'
)
print(f'Balance: {balance}')
package main
import (
"context"
"fmt"
"log"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient"
)
func main() {
client, err := ethclient.Dial("https://api-zksync-era-mainnet-full.n.dwellir.com/YOUR_API_KEY")
if err != nil {
log.Fatal(err)
}
contractAddress := common.HexToAddress("0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb")
data := common.FromHex("0x70a08231000000000000000000000000742d35Cc6634C0532925a3b844Bc9e7595f0bEb")
msg := ethereum.CallMsg{
To: &contractAddress,
Data: data,
}
result, err := client.CallContract(context.Background(), msg, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Result: 0x%x\n", result)
}
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