eth_feeHistory - Ethereum
Retrieve historical gas fee data using eth_feeHistory. Useful for transaction analysis, optimization, and planning by providing gas fees and usage ratios for a specified block range.
The eth_feeHistory method is part of the Ethereum JSON-RPC API and allows you to retrieve historical gas information for Ethereum transactions
This method returns data on gas fees and usage ratios for a specified range of blocks, which can be used for transaction analysis, optimization, and other blockchain-related tasks. This method is part of the Core API for Ethereum and uses JSON RPC to communicate with the blockchain. It provides useful data for gas optimization and transaction planning.
Supported Networks
The eth_feeHistory RPC Ethereum method supports the following network types:
Mainnet
Testnet: Sepolia, Holesk
Parameters:
DATA, 8 Bytes — Number of blocks in the requested range.
DATA, 32 Bytes — The latest block in the requested range.
DATA, 32 Bytes — An optional monotonically increasing list of percentile values to sample from each block’s effective priority fees per gas in ascending order, weighted by gas used.
Request
URL
To make a request, you need to send a JSON object with the jsonrpc, method, and params fields. Here is an example of how to make a request using curl:
Response
The server responds with a JSON object containing the requested gas fee history and related information. Here is an example of a typical response:
Response Description:
baseFeePerGas: An array of base fees per gas for each block in the requested range.
gasUsedRatio: An array representing the gas usage ratio for each block.
oldestBlock: The number of the oldest block in the requested range.
reward: An array containing reward information for each block for the specified percentiles.
Use Case:
Let's say you're a decentralized application (DApp) developer who wants to optimize the gas fees for users interacting with your smart contract. By using the eth_feeHistory method, you can retrieve historical gas data to predict the future gas prices and set a more efficient transaction fee for your users.
Code Example :
You can also make requests to the eth_feeHistory method programmatically using Python. Below is an example using the requests library:
This script sends a request to the eth_feeHistory method and prints the returned historical gas information. Make sure to replace <ACCESS-TOKEN> with your actual API token.
Common Errors:
eth_feeHistory error: You might encounter errors if the provided parameters are incorrect, or if the network is unreachable. Also, ensure that the block range you are querying is valid, and that your access token is correctly provided.\
Last updated