• Core
  • Actions
  • watchPublicClient

watchPublicClient

Action for subscribing to PublicClient changes.

import { watchPublicClient } from '@wagmi/core'

Usage

By default, the callback will be invoked when Public Client changes.

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

Return Value

unwatch is a function that can be called to unsubscribe from the Public Client change event.

Configuration

chainId (optional)

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

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