clawchain/wagmi/site/vue/api/composables/useWatchContractEvent.md

2.5 KiB

useWatchContractEvent

Composable that watches and returns emitted contract event logs.

Import

import { useWatchContractEvent } from '@wagmi/vue'

Usage

::: code-group

<script setup lang="ts">
import { useWatchContractEvent } from '@wagmi/vue'
import { abi } from './abi'

useWatchContractEvent({
  address: '0x6b175474e89094c44da98b954eedeac495271d0f',
  abi,
  eventName: 'Transfer',
  onLogs(logs) {
    console.log('New logs!', logs)
  },
})
</script>

<<< @/snippets/abi-event.ts[abi.ts] <<< @/snippets/vue/config.ts[config.ts] :::

Parameters

import { type UseWatchContractEventParameters } from '@wagmi/vue'

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.

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

import { type UseWatchContractEventReturnType } from '@wagmi/vue'

Hook returns void

Action