Documentation
/Hooks
/useBlockNumber
useBlockNumber
Hook for fetching block number.
import { useBlockNumber } from 'wagmi'
Usage
import { useBlockNumber } from 'wagmi'
const App = () => {
const [{ data, error, loading }, getBlockNumber] = useBlockNumber()
if (loading) return <div>Fetching block number…</div>
if (error) return <div>Error fetching block number</div>
return <div>Block number: {data}</div>
}
Return Values
result
{
data?: number
error?: Error
loading?: boolean
}
getBlockNumber
() => Promise<{ data?: number; error?: Error }>
Configuration
skip (optional)
Skips automatically fetching data on mount. Defaults to false
. Useful if you want to call getBlockNumber
manually at some other point.
import { useBlockNumber } from 'wagmi'
const App = () => {
const [{ data, error, loading }, getBlockNumber] = useBlockNumber({
skip: true,
})
return ...
}
watch (optional)
Watches and refreshes balance for new blocks.
import { useBlockNumber } from 'wagmi'
const App = () => {
const [{ data, error, loading }, getBlockNumber] = useBlockNumber({
watch: true
})
return ...
}