• Core
  • Actions
  • watchProvider

watchProvider

Action for subscribing to Provider changes.

import { watchProvider } from '@wagmi/core'

Usage

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

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

Return Value

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

Configuration

chainId (optional)

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

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