Skip to content

getBlockNumber

Returns the number of the most recent block seen.

Usage

example.ts
import { publicClient } from './client'
 
const blockNumber = await publicClient.getBlockNumber() 
Output: 69420n

Returns

bigint

The number of the block.

Parameters

cacheTime (optional)

Time (in ms) that cached block number will remain in memory.

const block = await publicClient.getBlockNumber({
  cacheTime: 4_000
})

By default, block numbers are cached for the period of the Client's cacheTime.

  • 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.

Example

Check out the usage of getBlockNumber in the live Fetching Blocks Example below.

JSON-RPC Method

eth_blockNumber