Xlayer API -Executes a new message call immediately without creating a transaction on the block chain.
Parameters
- Object - The transaction call object
- from: DATA, 20 Bytes - (optional) The address the transaction is sent from.
- to: DATA, 20 Bytes - The address the transaction is directed to.
- gas: QUANTITY - (optional) Integer of the gas provided for the transaction execution. eth_call consumes zero gas, but this parameter may be needed by some executions.
NOTE: this parameter has a cap of 550 Million Gwei per request. Reach out to us at [email protected] if you want to increase this limit.
- gasPrice: QUANTITY - (optional) Integer of the gasPrice used for each paid gas.
Note: most of our users (95%+) never set the gasPrice on eth_call.
- value: QUANTITY - (optional) Integer of the value sent with this transaction
- data: DATA - (optional) Hash of the method signature and encoded parameters. For details see Ethereum Contract ABI
- QUANTITY|TAG - Integer block number, or the string "latest", "earliest" or "pending" (see the default block parameter), OR the blockHash (in accordance with EIP-1898)
Note: the parameter is an object instead of a string and should be specified as:
{"blockHash": "0x``<some-hash>``"}
. Learn more here.Note: eth_call has a timeout restriction at the node level. Batching multiple eth_call together on-chain using pre-deployed smart contracts might result in unexpected timeouts that cause none of your calls to complete. Instead, consider serializing these calls, or using smaller batches if they fail with a node error code.
params: [
{
"to": "0x5A77f1443D16ee5761d310e38b62f77f726bC71c",
"data": "0x06fdde03"
},
"latest"
]
Example: Reading ERC20 Token Name
to
: WETH contract address on XLayerdata
:0x06fdde03
(function selector forname()
)- Block:
"latest"
(current state)
Returns
DATA - The return value of executed contract.
Example
Request
curl https://xlayer-mainnet.unifra.io/v1/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x5A77f1443D16ee5761d310e38b62f77f726bC71c","data":"0x06fdde03"},"latest"],"id":1}'
URL: https://xlayer-mainnet.unifra.io/v1/your-api-key
RequestType: POST
Body:
{
"jsonrpc":"2.0",
"method":"eth_call",
"params":[
{
"to": "0x5A77f1443D16ee5761d310e38b62f77f726bC71c",
"data": "0x06fdde03"
},
"latest"
],
"id":1
}
Result
{
"jsonrpc": "2.0",
"id": 1,
"result": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000d5772617070656420457468657200000000000000000000000000000000000000"
}
Result Explanation:
- The result is a hex-encoded string representing the token name
- Decoding the hex: "Wrapped Ether" (WETH token name)
- The first 32 bytes (
0x0000...0020
) indicate the string starts at offset 32 bytes - The second 32 bytes (
0x0000...000d
) indicate the string length is 13 characters - The third part contains the actual UTF-8 encoded string "Wrapped Ether"
- This is a read-only call that returns meaningful, repeatable data