Skip to content

watchEpochNumber

Watches and returns incoming epoch numbers.

Usage

example.ts
import { publicClient } from "./client";
 
const unwatch = publicClient.watchEpochNumber({
  onEpochNumber: (epochNumber) => {
    console.log(epochNumber);
  },
});
 
> 102224432n
> 102224435n
> 102224438n

Listener

(blockNumber: bigint) => void

The block number.

Returns

UnwatchFn

A function that can be invoked to stop watching for new block numbers.

Parameters

epochTag (optional)

  • Type latest_mined| latest_state | latest_confirmed | latest_checkpoint | earliest
  • Defaut latest_mined
const unwatch = publicClient.watchEpochNumber({
  epochTag: 'latest_mined', 
  onEpochNumber: (epochNumber) => {
    console.log(epochNumber);
  },
});

emitMissed (optional)

  • Type: boolean
  • Default: false

Whether or not to emit missed block numbers to the callback.

Missed block numbers may occur in instances where internet connection is lost, or the block time is lesser than the polling interval of the client.

const unwatch = publicClient.watchEpochNumber({
  emitMissed: true, 
  onEpochNumber: (epochNumber) => {
    console.log(epochNumber);
  },
});

emitOnBegin (optional)

  • Type: boolean
  • Default: false

Whether or not to emit the latest block number to the callback when the subscription opens.

const unwatch = publicClient.watchEpochNumber({
  emitMissed: true,
  emitOnBegin: true, 
  onEpochNumber: (epochNumber) => {
    console.log(epochNumber);
  },
});

poll (optional)

  • Type: boolean
  • Default: false for WebSocket Transports, true for non-WebSocket Transports

Whether or not to use a polling mechanism to check for new block numbers instead of a WebSocket subscription.

This option is only configurable for Clients with a WebSocket Transport.

TODO

pollingInterval (optional)

  • Type: number

Polling frequency (in ms). Defaults to Client's pollingInterval config.

const unwatch = publicClient.watchEpochNumber({
  emitMissed: true,
  emitOnBegin: true,
  pollingInterval: 12_000, 
  onEpochNumber: (epochNumber) => {
    console.log(epochNumber);
  },
});