watchPublicClient
Subscribe to Public Client changes.
Import
ts
import { watchPublicClient } from '@wagmi/core'
Usage
ts
import { watchPublicClient } from '@wagmi/core'
import { config } from './config'
const unwatch = watchPublicClient(config, {
onChange(client) {
console.log('Public Client changed!', client)
},
})
unwatch()
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Parameters
ts
import { type WatchPublicClientParameters } from '@wagmi/core'
onChange
onChange(client: GetPublicClientReturnType, prevClient: GetPublicClientReturnType): void
Callback function called when Public Client changes.
ts
import { watchPublicClient } from '@wagmi/core'
import { config } from './config'
const unwatch = watchPublicClient(config, {
onChange(client) {
console.log('Public Client changed!', client)
},
})
unwatch()
ts
import { http, createConfig } from '@wagmi/core'
import { mainnet, sepolia } from '@wagmi/core/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})
Return Type
ts
import { type WatchPublicClientReturnType } from '@wagmi/core'
Function for cleaning up watcher.