eth_feeHistory - Ethereum
Returns a collection of historical gas information
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 fee per gas data points from a single block. All zeroes are returned if the block is empty.
Example
Request
alchemyweb3.js
ethers.js
web3.py
Curl
Postman
1
// Installation instructions: https://github.com/alchemyplatform/alchemy-web3
2
3
async function main() {
4
// alchemy-token-api/alchemy-web3-script.js
5
import { createAlchemyWeb3 } from "@alch/alchemy-web3";
6
7
// Replace with your Alchemy API key:
8
const apiKey = "demo";
9
10
// Initialize an alchemy-web3 instance:
11
const web3 = createAlchemyWeb3(
12
`https://eth-mainnet.g.alchemy.com/v2/${apiKey}`,);
13
14
// Query the blockchain (replace example parameters)
15
const hist = await web3.eth.feeHistory({
16
block_count: 4,
17
newest_block: "latest",
18
reward_percentiles: [25, 75],
19
})
20
21
// Print the output to console
22
console.log(hist);
23
}
24
25
main();
Copied!
1
// Installation instructions: https://docs.ethers.io/v5/getting-started/#installing
2
3
async function main() {
4
const { ethers } = require("ethers");
5
6
// Replace with your Alchemy API key:
7
const apiKey = "demo";
8
9
// Initialize an ethers instance
10
const provider = new ethers.providers.JsonRpcProvider('https://eth-mainnet.alchemyapi.io/v2/${apiKey}',);
11
12
// Query the blockchain (replace example parameters)
13
const hist = await provider.feeHistory({
14
block_count: 4,
15
newest_block: "latest",
16
reward_percentiles: [25, 75],
17
})
18
19
// Print the output to console
20
console.log(hist);
21
}
22
23
main()
Copied!
1
# Installation Instructions: https://web3py.readthedocs.io/en/latest/quickstart.html#installation
2
3
from web3 import Web3, HTTPProvider
4
5
#Replace with your Alchemy API key:
6
const apiKey = "demo";
7
8
# Initialize a Web3.py instance
9
web3 = Web3(Web3.HTTPProvider('https://eth-mainnet.alchemyapi.io/v2/${apiKey}'))
10
11
# Query the blockchain (replace example parameters)
12
hist = web3.eth.fee_history({
13
'block_count': 4,
14
'newest_block': "latest",
15
'reward_percentiles': [25, 75],
16
})
17
18
# Print the output to console
19
print(hist)
Copied!
1
curl https://eth-rinkeby.alchemyapi.io/v2/your-api-key \
2
-X POST \
3
-H "Content-Type: application/json" \
4
-d '{"jsonrpc":"2.0","method":"eth_feeHistory","params":[4, "latest", [25, 75]],"id":1}'
Copied!
1
URL: https://eth-mainnet.alchemyapi.io/v2/your-api-key
2
RequestType: POST
3
Body:
4
{
5
"jsonrpc":"2.0",
6
"method":"eth_feeHistory",
7
"params":[4, "latest", [25, 75]],
8
"id":1
9
}
Copied!
Result
1
{
2
"id": "1",
3
"jsonrpc": "2.0",
4
"result": {
5
"oldestBlock": 10762137,
6
"reward": [
7
[
8
"0x4a817c7ee",
9
"0x4a817c7ee"
10
], [
11
"0x773593f0",
12
"0x773593f5"
13
], [
14
"0x0",
15
"0x0"
16
], [
17
"0x773593f5",
18
"0x773bae75"
19
]
20
],
21
"baseFeePerGas": [
22
"0x12",
23
"0x10",
24
"0x10",
25
"0xe",
26
"0xd"
27
],
28
"gasUsedRatio": [
29
0.026089875,
30
0.406803,
31
0,
32
0.0866665
33
]
34
}
35
}
Copied!
Ethereum API
Alchemy Documentation
Copy link