eth_feeHistory - Ethereum

Returns a collection of historical gas information.

Don’t have an API key?

Start using this API in your app today.

Returns a collection of historical gas information from which you can decide what to submit as your maxFeePerGas and/or maxPriorityFeePerGas. This method was introduced with EIP 1559.

Parameters

  • blockCount - Number of blocks in the requested range. Between 1 and 1024 blocks can be requested in a single query. Less than requested may be returned if not all blocks are available.
  • newestBlock - Highest number block of the requested range.
  • rewardPercentiles - (optional) 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.

Returns

Object

  • oldestBlock - Lowest number block of the returned range.
  • baseFeePerGas - An array of block base fees per gas. This includes the next block after the newest of the returned range, because this value can be derived from the newest block. Zeroes are returned for pre-EIP-1559 blocks.
  • gasUsedRatio - An array of block gas used ratios. These are calculated as the ratio of gasUsed and gasLimit.
  • reward - (Optional) An array of effective priority fees per gas data points from a single block. All zeroes are returned if the block is empty.
  • baseFeePerBlobGas - An array of base fees per blob gas for blocks. This includes the next block following the newest in the returned range, as this value can be derived from the latest block. For blocks before EIP-4844, zeroes are returned.
  • blobGasUsedRatio - An array showing the ratios of blob gas used in blocks. These ratios are calculated by dividing blobGasUsed by the maximum blob gas per block.

Example

Request

// Setup: npm install alchemy-sdk
// Github: https://github.com/alchemyplatform/alchemy-sdk-js
const { Network, Alchemy } = require("alchemy-sdk");

// Optional config object, but defaults to demo api-key and eth-mainnet.
const settings = {
  apiKey: "demo", // Replace with your Alchemy API Key.
  network: Network.ETH_MAINNET, // Replace with your network.
};
const alchemy = new Alchemy(settings);

async function main() {
  // Using send method from alchemy-sdk with specific transaction details
  const res = await alchemy.core.send("eth_feeHistory", ["0x5", "latest", []]);

  console.log(res);
}

main();
// Installation instructions: https://docs.ethers.io/v5/getting-started/#installing

async function main() {
   const { ethers } = require("ethers");
   
	// Replace with your Alchemy API key:
	const apiKey = "demo";

	// Initialize an ethers instance
	const provider = new ethers.providers.JsonRpcProvider('https://eth-mainnet.g.alchemy.com/v2/${apiKey}',);

	// Query the blockchain (replace example parameters)
   	const hist = await provider.feeHistory({
	    block_count: 4,
	    newest_block: "latest",
	    reward_percentiles: [25, 75],
	  }) 

	// Print the output to console
  	console.log(hist);
   }

main()
# Installation Instructions: https://web3py.readthedocs.io/en/latest/quickstart.html#installation

from web3 import Web3, HTTPProvider

#Replace with your Alchemy API key:
const apiKey = "demo";

# Initialize a Web3.py instance
web3 = Web3(Web3.HTTPProvider('https://eth-mainnet.g.alchemy.com/v2/${apiKey}'))

# Query the blockchain (replace example parameters)
hist = web3.eth.fee_history({
	    'block_count': 4,
	    'newest_block': "latest",
	    'reward_percentiles': [25, 75],
		})

# Print the output to console
print(hist)
curl https://eth-mainnet.g.alchemy.com/v2/your-api-key \
-X POST \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"eth_feeHistory","params":[4, "latest", [25, 75]],"id":1}'
URL: https://eth-mainnet.g.alchemy.com/v2/your-api-key
RequestType: POST
Body: 
{
    "jsonrpc":"2.0",
    "method":"eth_feeHistory",
    "params":[4, "latest", [25, 75]],
    "id":1
}

Result

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "oldestBlock": "0x130b1e6",
    "reward": [
      ["0x5041e1e", "0xdd221b80"],
      ["0x5041e1e", "0xb8346df0"],
      ["0x55d4a80", "0xb2d05e00"],
      ["0x4dd9818", "0x3b9aca00"]
    ],
    "baseFeePerGas": [
      "0x52d80a82c",
      "0x50f43f659",
      "0x50012de8d",
      "0x4e30357d6",
      "0x57efff9e7"
    ],
    "gasUsedRatio": [
      0.40875283333333334,
      0.45308523333333334,
      0.4091907,
      0.9987537
    ],
    "baseFeePerBlobGas": ["0x1", "0x1", "0x1", "0x1", "0x1"],
    "blobGasUsedRatio": [0.5, 1, 0.6666666666666666, 1]
  }
}

❗️

The below parameter inputs do not work, please reference the section above instead.

Language
URL
ReadMe