EthereumMethods

eth_feeHistory

Ethereum eth_feeHistory method documentation for the NaaS API.

eth_createAccessList

Overview

The 'eth_feeHistory' method returns historical gas information, allowing users to track Ethereum gas trends over time.

Request

shell

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_feeHistory",
  "params": [
    4,
    4,
    4
  ]
}
'

csharp

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_feeHistory\",\"params\":[4,4,4]}", false);
var response = await client.PostAsync(request);

Console.WriteLine("{0}", response.Content); }

php

<?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_feeHistory',
'params' => [
4,
4,
4
]
]),
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;
}
?>

python

 import requests

url = "https://ethereum-mainnet-geth-archive.node.coinapi.io"

payload = {
    "id": 1,
    "jsonrpc": "2.0",
    "method": "eth_feeHistory",
    "params": [4, 4, 4]
}
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)

javascript

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_feeHistory', params: [4, 4, 4]})
};

fetch('https://ethereum-mainnet-geth-archive.node.coinapi.io', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));

go

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_feeHistory\",\"params\":[4,4,4]}")

	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))

}

ruby

 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_feeHistory\",\"params\":[4,4,4]}"

response = http.request(request)
puts response.read_body

java

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\"id\":1,\"jsonrpc\":\"2.0\",\"method\":\"eth_feeHistory\",\"params\":[4,4,4]}");
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

  • blockCount: (integer) Specifies the number of blocks in the requested range. Users can request between 1 and 1024 blocks in a single query. If blocks in the specified block range are unavailable, the fee history for the available blocks will be returned.

  • newestBlock: (string) This represents the highest number block of the requested range. It can be an integer or one of the string tags: latest, earliest, or pending.

  • array of integers (optional): This is a monotonically increasing list of percentile values to sample from each block's effective priority fees per gas in ascending order, weighted by gas used.

Response

{
  "jsonrpc": "2.0",
  "id": 0,
  "result": {
    "oldestBlock": "0xfd6a75",
    "reward": [
      ["0x3b9aca00", "0x3b9aca00", "0x59682f00"],
      ["0x3b9aca00", "0x3b9aca00", "0x77359400"],
      ["0x3b9aca00", "0x3b9aca00", "0x3b9aca00"],
      ["0x2e7ddb00", "0x3b9aca00", "0x77359400"],
      ["0x3b9aca00", "0x3b9aca00", "0x59682f00"]
    ],
    "baseFeePerGas": [
      "0x4c9d974c3",
      "0x4c38a847a",
      "0x49206d475",
      "0x47ac58b63",
      "0x471e805d8",
      "0x46f5f64a6"
    ],
    "gasUsedRatio": [
      0.4794155666666667, 0.3375966, 0.42049746666666665, 0.4690773,
      0.49109343333333333
    ]
  }
}
  • oldestBlock: This is the lowest number block of the returned range, expressed as a hexadecimal number.

  • baseFeePerGas: An array of block base fees per gas. This includes an extra block value, which is the next block after the newest block in the returned range. Blocks created before EIP-1559 will return zeroes.

  • gasUsedRatio: An array of block gas used ratios. These ratios are calculated as the ratio of 'gasUsed' and 'gasLimit'.

  • reward: This is an array of effective priority fee per gas data points from a single block. If the block is empty, all zeroes are returned.

Service StatusGitHub SDK