eth_createAccessList
Overview
The 'eth_estimateGas' method generates and returns an estimate of how much gas is necessary for a transaction to complete. It's important to note that this transaction will not be added to the blockchain. The estimate might be significantly more than the actual gas used due to various reasons, including EVM mechanics and node performance.
Gas Parameter Limitation
To ensure the optimal performance and security of our API, the gas parameter in the eth_estimateGas method (as well as in eth_call) is capped at 10 times (1000%) the current block gas limit. If you're testing this in a local environment (e.g., ganache, besu, geth), you can replicate this behavior using the rpc.gascap command-line option.
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_estimateGas",
"params": [
{
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x00",
"gasPrice": "0x09184e72a000",
"value": "0x00",
"data": "0x"
},
{
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x00",
"gasPrice": "0x09184e72a000",
"value": "0x00",
"data": "0x"
}
]
}
'
using RestSharp; {
var options = new RestClientOptions("https://ethereum-mainnet-geth-archive.node.coinapi.io");
var client = new RestClient(options);
var request = new RestRequest("");
request.AddHeader("accept", "application/json", "X-CoinAPI-Key: 73034021-THIS-IS-SAMPLE-KEY");
request.AddJsonBody("{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_estimateGas\",\"params\":[{\"to\":\"0xd46e8dd67c5d32be8058bb8eb970870f07244567\",\"gas\":\"0x00\",\"gasPrice\":\"0x09184e72a000\",\"value\":\"0x00\",\"data\":\"0x\"},{\"to\":\"0xd46e8dd67c5d32be8058bb8eb970870f07244567\",\"gas\":\"0x00\",\"gasPrice\":\"0x09184e72a000\",\"value\":\"0x00\",\"data\":\"0x\"}]}", false);
var response = await client.PostAsync(request);
Console.WriteLine("{0}", response.Content); }
<?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_estimateGas',
'params' => [
[
'to' => '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
'gas' => '0x00',
'gasPrice' => '0x09184e72a000',
'value' => '0x00',
'data' => '0x'
],
[
'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_estimateGas",
"params": [
{
"to": "0xd46e8dd67c5d32be8058bb8eb970870f07244567",
"gas": "0x00",
"gasPrice": "0x09184e72a000",
"value": "0x00",
"data": "0x"
},
{
"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_estimateGas',
params: [
{
to: '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
gas: '0x00',
gasPrice: '0x09184e72a000',
value: '0x00',
data: '0x'
},
{
to: '0xd46e8dd67c5d32be8058bb8eb970870f07244567',
gas: '0x00',
gasPrice: '0x09184e72a000',
value: '0x00',
data: '0x'
}
]
})
};
fetch('https://ethereum-mainnet-geth-archive.node.coinapi.io', 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_estimateGas\",\"params\":[{\"to\":\"0xd46e8dd67c5d32be8058bb8eb970870f07244567\",\"gas\":\"0x00\",\"gasPrice\":\"0x09184e72a000\",\"value\":\"0x00\",\"data\":\"0x\"},{\"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_estimateGas\",\"params\":[{\"to\":\"0xd46e8dd67c5d32be8058bb8eb970870f07244567\",\"gas\":\"0x00\",\"gasPrice\":\"0x09184e72a000\",\"value\":\"0x00\",\"data\":\"0x\"},{\"to\":\"0xd46e8dd67c5d32be8058bb8eb970870f07244567\",\"gas\":\"0x00\",\"gasPrice\":\"0x09184e72a000\",\"value\":\"0x00\",\"data\":\"0x\"}]}"
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_estimateGas\",\"params\":[{\"to\":\"0xd46e8dd67c5d32be8058bb8eb970870f07244567\",\"gas\":\"0x00\",\"gasPrice\":\"0x09184e72a000\",\"value\":\"0x00\",\"data\":\"0x\"},{\"to\":\"0xd46e8dd67c5d32be8058bb8eb970870f07244567\",\"gas\":\"0x00\",\"gasPrice\":\"0x09184e72a000\",\"value\":\"0x00\",\"data\":\"0x\"}]}");
Request request = new Request.Builder()
.url("https://ethereum-mainnet-geth-archive.node.coinapi.io")
.post(body)
.addHeader("accept", "application/json")
.addHeader("content-type", "application/json")
.addHeader("X-CoinAPI-Key", "73034021-THIS-IS-SAMPLE-KEY")
.build();
Response response = client.newCall(request).execute();
Request Parameters
-
block number: [required] A string representing a block number, or one of the string tags: 'latest', 'earliest', or 'pending'.
-
TRANSACTION CALL OBJECT [required]:
- 'from': [optional] 20 Bytes - The address the transaction originates from.
- 'to': 20 Bytes - The destination address of the transaction.
- 'gas': [optional] Hexadecimal value representing the gas provided for the transaction execution. While eth_estimateGas consumes no gas, this parameter might be needed in certain scenarios.
- 'gasPrice': [optional] Hexadecimal value of the gas price for each unit of gas.
- 'maxPriorityFeePerGas': [optional] Maximum fee, in Wei, the sender is willing to pay per gas above the base fee.
- 'maxFeePerGas': [optional] Maximum total fee (base fee + priority fee), in Wei, the sender is willing to pay per gas.
- 'value': [optional] Hexadecimal value of the amount sent with the transaction.
- 'data': [optional] Hash of the method signature and encoded parameters.
If no gas limit is specified, the system uses the block gas limit from the pending block as an upper bound. This means the returned estimate might not be sufficient if the required gas exceeds the pending block gas limit.
Response
{
"jsonrpc": "2.0",
"id": 1,
"result": "0xb1770efb14906e509893b6190359658208ae64d0c56e22f748a1b0869885559e"
}
A hexadecimal representation of the estimated gas for the provided transaction.
If the call results in an EVM REVERT operation, an error response is returned with the revert reason pre-decoded as a string