curl --request POST \
--url https://nd-363-550-219.p2pify.com/942aad90bb6a082676497030b81e40ba \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_call",
"id": 1,
"params": [
{
"to": "0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9",
"data": "0x18160ddd"
},
"latest"
]
}'
{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}
curl --request POST \
--url https://nd-363-550-219.p2pify.com/942aad90bb6a082676497030b81e40ba \
--header 'Content-Type: application/json' \
--data '{
"jsonrpc": "2.0",
"method": "eth_call",
"id": 1,
"params": [
{
"to": "0x4F9A0e7FD2Bf6067db6994CF12E4495Df938E6e9",
"data": "0x18160ddd"
},
"latest"
]
}'
{
"jsonrpc": "<string>",
"id": 123,
"result": "<string>"
}
eth_call
to call the totalSupply()
method from the WETH smart contract on Polygon zkEVM. You can use the Chainstack EVM Knife to convert the result.object
— the transaction call object:
from
— (optional) the address string used to send the transaction.to
— the string of the address to which the transaction is directed, a wallet, or a smart contract.gas
— (optional) the maximum amount of gas that can be used by the transaction.gasprice
— (optional) the amount of gas price the sender is willing to pay for each gas unit in Wei.value
— (optional) the value sent with this transaction, encoded as hexadecimal.data
— (optional) additional data to be sent with the call, usually used to invoke functions from smart contracts as a string of the hash of the method signature and encoded parameters. See the Ethereum Contract ABI.quantity or tag
— the integer of a block encoded as hexadecimal or the string with:
latest
— the most recent block in the blockchain and the current state of the blockchain at the most recent blockearliest
— the earliest available or genesis blockpending
— the pending state and transactions block. The current state of transactions that have been broadcast to the network but have not yet been included in a block.data
— the result of executing the specified call on the Ethereum Virtual Machine (EVM), encoded as a hexadecimal string.eth_call
code exampleseth_call
to simulate a transfer or a smart contract transaction, the sender account must have a sufficient balance to cover the associated gas fee.
const { Web3 } = require('web3');
const NODE_URL = "CHAINSTACK_NODE_URL";
const web3 = new Web3(NODE_URL);
async function simulateTransfer() {
try {
// Define the accounts to transfer between
const fromAddress = "0x3eb6347f6282E78F778C23c97E8657F5EE5378E0";
const toAddress = "0x19e7e376e7c213b7e7e7e46cc70a5dd086daff2a";
// Define the value to transfer (converted to Wei)
const value = web3.utils.toWei("100", "ether");
// Build transaction object
const transactionObject = {
from: fromAddress,
to: toAddress,
gas: 21000, // 21000 is the standard for a regular tranfer
value: value,
data: ""
}
// Use eth_call to simulate the transfer on the latest block
const result = await web3.eth.call({
transactionObject
}, "latest");
console.log(`Transaction hash: ${result}`);
} catch (error) {
console.error(`Error: ${error.message}`);
}
}
simulateTransfer();
0x
, indicating a successful transaction. This implies that the transaction will be executed without errors when the code is used to send the transaction.
eth_call
is calling smart contract functions. For example, interact with an ERC-20 token smart contract deployed on the zlEVM network and retrieve the balance of a specific account.The result of the call.
The response is of type object
.