getFeeHistory โ
Returns a collection of historical gas information.
Usage โ
ts
import { publicClient } from './client'
const feeHistory = await publicClient.getFeeHistory({ 
  blockCount: 4,
  rewardPercentiles: [25, 75]
})
ts
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
export const publicClient = createPublicClient({
  chain: mainnet,
  transport: http()
})
Returns โ
The fee history.
Parameters โ
blockCount โ
- Type: 
number 
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.
ts
const feeHistory = await publicClient.getFeeHistory({
  blockCount: 4, 
  rewardPercentiles: [25, 75]
})
rewardPercentiles โ
- Type: 
number[] 
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.
ts
const feeHistory = await publicClient.getFeeHistory({
  blockCount: 4,
  rewardPercentiles: [25, 75] 
})
blockNumber (optional) โ
- Type: 
number 
Highest number block of the requested range.
ts
const feeHistory = await publicClient.getFeeHistory({
  blockCount: 4,
  blockNumber: 1551231n, 
  rewardPercentiles: [25, 75]
})
blockTag (optional) โ
- Type: 
'latest' | 'earliest' | 'pending' | 'safe' | 'finalized' - Default: 
'latest' 
Highest number block of the requested range.
ts
const feeHistory = await publicClient.getFeeHistory({
  blockCount: 4,
  blockTag: 'safe', 
  rewardPercentiles: [25, 75]
})
JSON-RPC Method โ
- Calls 
eth_feeHistory.