• Core
  • Actions
  • watchBlockNumber

watchBlockNumber

Action for subscribing to block number changes.

import { watchBlockNumber } from '@wagmi/core'

Usage

By default, the callback will be invoked when Provider/WebSocketProvider changes.

import { watchBlockNumber } from '@wagmi/core'
 
const unwatch = watchBlockNumber(
  {
    chainId: 1,
  },
  (blockNumber) => console.log(blockNumber),
)

Configuration

chainId (optional)

Force a specific chain id for the request. The wagmi Client's ethers provider must be set up as a chain-aware function for this to work correctly.

import { watchBlockNumber } from '@wagmi/core'
 
const unwatch = watchBlockNumber(
  {
    chainId: 1,
  },
  (blockNumber) => console.log(blockNumber),
)

listen (optional)

Listen to network for block number changes.

import { watchBlockNumber } from '@wagmi/core'
 
const unwatch = watchBlockNumber(
  {
    listen: true,
  },
  (blockNumber) => console.log(blockNumber),
)