useFeeData
Hook for fetching fee information.
import { useFeeData } from 'wagmi'
Usage
import { useFeeData } from 'wagmi'
const App = () => { const [{ data, error, loading }, getFeeData] = useFeeData()
if (loading) return <div>Fetching fee data…</div> if (error) return <div>Error fetching fee data</div> return <div>{data?.formatted?.maxFeePerGas}</div>}
Return Values
result
{ data?: { gasPrice: BigNumber maxFeePerGas: BigNumber maxPriorityFeePerGas: BigNumber formatted: { gasPrice: string maxFeePerGas: string maxPriorityFeePerGas: string } } error?: Error loading?: boolean}
getFeeData
() => Promise<{ data?: { gasPrice: BigNumber maxFeePerGas: BigNumber maxPriorityFeePerGas: BigNumber } error?: Error}>
Configuration
formatUnits (optional)
Formats balance using ethers.js units. Defaults to wei
.
import { useFeeData } from 'wagmi'
const App = () => { const [{ data, error, loading }, getFeeData] = useFeeData({ formatUnits: 'gwei', })
return ...}
skip (optional)
Skips automatically fetching data on mount. Defaults to false
. Useful if you want to call getFeeData
manually at some other point.
import { useFeeData } from 'wagmi'
const App = () => { const [{ data, error, loading }, getFeeData] = useFeeData({ skip: true, })
return ...}
watch (optional)
Watches and refreshes balance for new blocks.
import { useFeeData } from 'wagmi'
const App = () => { const [{ data, error, loading }, getFeeData] = useFeeData({ watch: true })
return ...}