• Core
  • Actions
  • watchWebSocketProvider

watchWebSocketProvider

Action for subscribing to WebSocketProvider changes.

import { watchWebSocketProvider } from '@wagmi/core'

Usage

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

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

Return Value

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

Configuration

chainId (optional)

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

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