useContractEvents

Watches contract events and returns the parsed logs.

Example

Using event extensions

The thirdweb/extesions export contains event definitions for many popular contracts. You can use these event definitions to watch for specific events with a type-safe API.

import { useContractEvents } from "thirdweb/react";
import { tokensClaimedEvent } from "thirdweb/extensions/erc721";
const account = useActiveAccount();
const contractEvents = useContractEvents({
contract,
events: [tokensClaimedEvent({ claimer: account?.address })],
});

Using custom events

You can also watch for custom events by passing an array of prepared events .

import { useContractEvents } from "thirdweb/react";
import { prepareEvent } from "thirdweb";
const myEvent = prepareEvent({
signature: "event MyEvent(uint256 myArg)",
});
const contractEvents = useContractEvents({
contract,
events: [myEvent],
});

Parameters

Returns

The contract events of the watched contract events.