Skip to content

useWatchContractEvent ​

Primitive that watches and returns emitted contract event logs.

Import ​

ts
import { useWatchContractEvent } from '@wagmi/solid'

Usage ​

tsx
import { useWatchContractEvent } from '@wagmi/solid'
import { abi } from './abi'

function App() {
  useWatchContractEvent(() => ({
    address: '0x6b175474e89094c44da98b954eedeac495271d0f',
    abi,
    eventName: 'Transfer',
    onLogs(logs) {
      console.log('New logs!', logs)
    },
  }))
}
ts
import { createConfig, http } from '@wagmi/solid'
import { mainnet, sepolia } from '@wagmi/solid/chains'

export const config = createConfig({
  chains: [mainnet, sepolia],
  transports: {
    [mainnet.id]: http(),
    [sepolia.id]: http(),
  },
})

Parameters ​

ts
import { useWatchContractEvent } from '@wagmi/solid'

useWatchContractEvent.Parameters
useWatchContractEvent.SolidParameters

Parameters are passed as a getter function to maintain Solid reactivity.

ts
useWatchContractEvent(() => ({
  address: '0x...',
  abi,
  eventName: 'Transfer',
  onLogs(logs) { ... },
}))

abi ​

Abi

The contract's ABI. Check out the TypeScript docs for how to set up ABIs for maximum type inference and safety.

address ​

Address | undefined

The contract's address.

args ​

object | readonly unknown[] | undefined

  • Arguments to pass when calling the contract.
  • Inferred from abi and eventName.

batch ​

boolean | undefined

  • Whether or not the events should be batched on each invocation.
  • Defaults to true.

chainId ​

config['chains'][number]['id'] | undefined

ID of chain to use when fetching data.

config ​

Config | undefined

Config to use instead of retrieving from the nearest WagmiProvider.

enabled ​

boolean | undefined

  • Whether or not to watch for events.
  • Defaults to true.

eventName ​

string

  • Event to listen for the contract.
  • Inferred from abi.

onError ​

((error: Error) => void) | undefined

Error thrown from getting the block number.

onLogs ​

(logs: Log[], prevLogs: Log[] | undefined) => void

Callback for when logs changes.

poll ​

boolean | undefined

  • Whether or not to use a polling mechanism to check for new blocks instead of a WebSocket subscription.
  • Defaults to false for WebSocket Clients, and true for non-WebSocket Clients.

pollingInterval ​

number | undefined

strict ​

boolean | undefined

  • Defaults to false.

syncConnectedChain ​

boolean | undefined

Return Type ​

ts
import { useWatchContractEvent } from '@wagmi/solid'

useWatchContractEvent.ReturnType

Primitive returns void.

Type Inference ​

With abi setup correctly, TypeScript will infer the correct types for eventName, args, and onLogs parameters. See the Wagmi TypeScript docs for more information.

Action ​

Released under the MIT License.