clawchain/wagmi/site/react/api/hooks/useFeeHistory.md

4.0 KiB

title, description
title description
useFeeHistory Hook for fetching a collection of historical gas information.

useFeeHistory

Hook for fetching a collection of historical gas information.

Import

import { useFeeHistory } from 'wagmi'

Usage

::: code-group

import { useFeeHistory } from 'wagmi'

function App() {
  const result = useFeeHistory({
    blockCount: 4,
    rewardPercentiles: [25, 75]
})
}

<<< @/snippets/react/config.ts[config.ts] :::

Parameters

import { type UseFeeHistoryParameters } from 'wagmi'

blockCount

number | undefined

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.

::: code-group

import { useFeeHistory } from 'wagmi'

function App() {
  const result = useFeeHistory({
    blockCount: 4, // [!code focus]
    rewardPercentiles: [25, 75]
  })
}

<<< @/snippets/react/config.ts[config.ts] :::

rewardPercentiles

number[] | undefined

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.

::: code-group

import { useFeeHistory } from 'wagmi'

function App() {
  const result = useFeeHistory({
    blockCount: 4,
    rewardPercentiles: [25, 75] // [!code focus]
  })
}

<<< @/snippets/react/config.ts[config.ts] :::

blockNumber

bigint | undefined

Highest number block of the requested range.

::: code-group

import { useFeeHistory } from 'wagmi'

function App() {
  const result = useFeeHistory({
    blockCount: 4,
    blockNumber: 1551231n, // [!code focus]
    rewardPercentiles: [25, 75]
  })
}

<<< @/snippets/react/config.ts[config.ts] :::

blockTag

'latest' | 'earliest' | 'pending' | 'safe' | 'finalized' | undefined

Block tag of the highest number block of the requested range.

::: code-group

import { useFeeHistory } from 'wagmi'

function App() {
  const result = useFeeHistory({
    blockCount: 4,
    blockTag: 'safe', // [!code focus]
    rewardPercentiles: [25, 75]
  })
}

<<< @/snippets/react/config.ts[config.ts] :::

chainId

config['chains'][number]['id'] | undefined

ID of chain to use when fetching data.

::: code-group

import { useFeeHistory } from 'wagmi'
import { mainnet } from '@wagmi/core/chains'

function App() {
  const result = useFeeHistory({
    blockCount: 4,
    chainId: mainnet.id, // [!code focus]
    rewardPercentiles: [25, 75]
  })
}

<<< @/snippets/react/config.ts[config.ts] :::

config

Config | undefined

Config to use instead of retrieving from the nearest WagmiProvider.

::: code-group

import { useFeeHistory } from 'wagmi'
import { config } from './config' // [!code focus]

function App() {
  const result = useFeeHistory({
    blockCount: 4,
    rewardPercentiles: [25, 75]
    config, // [!code focus]
  })
}

<<< @/snippets/react/config.ts[config.ts] :::

scopeKey

string | undefined

Scopes the cache to a given context. Hooks that have identical context will share the same cache.

::: code-group

import { useFeeHistory } from 'wagmi'
import { config } from './config' // [!code focus]

function App() {
  const result = useFeeHistory({
    blockCount: 4,
    rewardPercentiles: [25, 75]
    scopeKey: 'foo', // [!code focus]
  })
}

<<< @/snippets/react/config.ts[config.ts] :::

Return Type

import { type UseFeeHistoryReturnType } from 'wagmi'

Action