Skip to Content
dApps

eth_call

Executes a new message call immediately without creating a transaction on the blockchain. This is used for reading data from smart contracts.


Parameters

IndexTypeDescription
0objectTransaction call object
1stringBlock number or tag (latest, earliest, pending)

Transaction Call Object

FieldTypeRequiredDescription
tostringYesContract address
datastringNoEncoded function call data
fromstringNoSender address (for context)
gasstringNoGas limit (hex)
gasPricestringNoGas price (hex)
valuestringNoValue in wei (hex)

Returns

string - The return data of the call (hex encoded)


Example

Read ERC-20 Balance

// balanceOf(address) selector: 0x70a08231 const address = '0xYourAddress...'.slice(2).padStart(64, '0') const data = '0x70a08231' + address const balance = await window.$onekey.ethereum.request({ method: 'eth_call', params: [{ to: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // USDC data: data }, 'latest'] }) console.log('Balance:', BigInt(balance).toString())

Read Contract Name

// name() selector: 0x06fdde03 const name = await window.$onekey.ethereum.request({ method: 'eth_call', params: [{ to: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', data: '0x06fdde03' }, 'latest'] }) // Decode the result (ABI encoded string) // Decode `name` with your ABI library's string decoder. console.log('ABI-encoded contract name:', name)

Using ethers.js

import { Contract, BrowserProvider } from 'ethers' const provider = new BrowserProvider(window.$onekey.ethereum) const contract = new Contract( '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', ['function balanceOf(address) view returns (uint256)'], provider ) const balance = await contract.balanceOf('0xYourAddress...') console.log('USDC Balance:', balance.toString())

Errors

CodeMessageDescription
-32000Execution revertedContract call reverted
-32602Invalid paramsInvalid call parameters

Notes

  • This method does not consume gas or modify state
  • The from address is optional but may affect the result for some contracts
  • Choose a block tag appropriate for your use case; latest reflects the latest block visible to the endpoint
  • For complex contract interactions, consider using ethers.js or web3.js

The token-address examples are for Ethereum mainnet. Confirm the chain and substitute a complete 20-byte account address before encoding balanceOf.

Last updated on