getBlockNumber
Returns the number of the most recent block seen.
Import
ts
import { getBlockNumber } from 'viem'
Usage
ts
import { getBlockNumber } from 'viem'
import { publicClient } from '.'
const block = await getBlockNumber(publicClient)
// 69420n
Returns
bigint
The number of the block.
Parameters
maxAge (optional)
- Type:
number
- Default: Client's
pollingInterval
The maximum age (in ms) of the cached value.
ts
const block = await getBlockNumber(publicClient, {
maxAge: 4_000
})
By default, block numbers are cached for the period of the Client's pollingInterval
.
- Setting a value of above zero will make block number remain in the cache for that period.
- Setting a value of
0
will disable the cache, and always retrieve a fresh block number.