eth_call
Overview
The 'eth_call' method executes a new message call immediately without creating a transaction on the blockchain. This method is useful for querying data from the Ethereum blockchain without making any changes to the state.
Request
- shell
- csharp
- php
- python
- javascript
- go
- ruby
- java
curl --request POST \
--url https://ethereum-mainnet-geth-archive.node.coinapi.io \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY" \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x00",
"gasPrice": "0x09184e72a000",
"value": "0x00",
"data": "0x"}
]
}'
using System.Net.Http.Headers;
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://ethereum-mainnet-geth-archive.node.coinapi.io"),
Headers =
{
{ "accept", "application/json","X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY" },
},
Content = new StringContent("{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{\"to\":\"0xd46e8dd67c5d32be8058bb8eb970870f07244567\",\"gas\":\"0x00\",\"gasPrice\":\"0x09184e72a000\",\"value\":\"0x00\",\"data\":\"0x\"}]}")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
}
};
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync();
Console.WriteLine(body);
}
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://ethereum-mainnet-geth-archive.node.coinapi.io",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'id' => 1,
'jsonrpc' => '2.0',
'method' => 'eth_call',
'params' => [
[
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
'gas' => '0x00',
'gasPrice' => '0x09184e72a000',
'value' => '0x00',
'data' => '0x'
]
]
]),
CURLOPT_HTTPHEADER => [
"accept: application/json",
"content-type: application/json"
"X-CoinAPI-Key" => "73034021-THIS-IS-SAMPLE-KEY"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
import requests
url = "https://ethereum-mainnet-geth-archive.node.coinapi.io"
payload = {
"id": 1,
"jsonrpc": "2.0",
"method": "eth_call",
"params": [
{
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x00",
"gasPrice": "0x09184e72a000",
"value": "0x00",
"data": "0x"
}
]
}
headers = {
"accept": "application/json",
"content-type": "application/json"
"X-CoinAPI-Key" : "73034021-THIS-IS-SAMPLE-KEY"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)
const options = {
method: 'POST',
headers: {accept: 'application/json', 'content-type': 'application/json', 'X-CoinAPI-Key' : '73034021-THIS-IS-SAMPLE-KEY'},
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'eth_call',
params: [
{
to: '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
gas: '0x00',
gasPrice: '0x09184e72a000',
value: '0x00',
data: '0x'
}
]
})
};
fetch('https://eth-mainnet.g.alchemy.com/v2/docs-demo', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://ethereum-mainnet-geth-archive.node.coinapi.io"
payload := strings.NewReader("{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{\"to\":\"0xd46e8dd67c5d32be8058bb8eb970870f07244567\",\"gas\":\"0x00\",\"gasPrice\":\"0x09184e72a000\",\"value\":\"0x00\",\"data\":\"0x\"}]}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("accept", "application/json")
req.Header.Add("content-type", "application/json")
req.Header.Add("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}
require 'uri'
require 'net/http'
url = URI("https://ethereum-mainnet-geth-archive.node.coinapi.io")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["accept"] = 'application/json'
request["content-type"] = 'application/json'
request["X-CoinAPI-Key"] = '73034021-THIS-IS-SAMPLE-KEY'
request.body = {\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_accounts\"}
response = http.request(request)
puts response.read_body;
OkHttpClient client = new OkHttpClient();
{
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"params\":[{\"to\":\"0xd46e8dd67c5d32be8058bb8eb970870f07244567\",\"gas\":\"0x00\",\"gasPrice\":\"0x09184e72a000\",\"value\":\"0x00\",\"data\":\"0x\"}]}");
Request request = new Request.Builder()
.url("https://eth-mainnet.g.alchemy.com/v2/docs-demo")
.post(body)
.addHeader("accept", "application/json")
.addHeader("content-type", "application/json")
.build();
Response response = client.newCall(request).execute();
}
Gas Parameter Limitation
To ensure the stability of our platform and prevent potential abuse, the 'gas' parameter in "eth_estimateGas" and this "eth_call" method is capped at 10x (1000%) the current block gas limit.
Request Parameters
- "from": 20 bytes - [ Required ] Address the transaction is sent from.
- "to": 20 bytes - Address the transaction is directed to.
- 'gas': Hexadecimal value of the gas provided for the transaction execution. While 'eth_call' consumes zero gas, this parameter may be needed by some executions.
- 'gasPrice': Hexadecimal value of the gasPrice used for each paid gas.
- 'maxPriorityFeePerGas': Maximum fee, in Wei, the sender is willing to pay per gas above the base fee. (Relevant for EIP-1559 transactions)
- 'maxFeePerGas': Maximum total fee (base fee + priority fee), in Wei, the sender is willing to pay per gas. (Relevant for EIP-1559 transactions)
- 'value': Hexadecimal of the value sent with this transaction.
- 'data': Hash of the method signature and encoded parameters. Refer to the Ethereum contract ABI specification for more details.
- 'block parameter': [ Required ] A hexadecimal block number, or the string 'latest', 'earliest' or 'pending'.
Response
{
"jsonrpc": "2.0",
"id": 1,
"result": "0xb1770efb14906e509893b6190359658208ae64d0c56e22f748a1b0869885559e"
}
The returned value of the executed contract. If this call causes the EVM to execute a ''REVERT'' operation, an error response is returned with the revert reason pre-decoded as a string.
Was this section helpful?