watchContractEvents

Listens for contract events from the blockchain.

Example

Listen to all events for a contract

import { watchContractEvents } from "thirdweb";
const unwatch = watchContractEvents({
contract: myContract,
onEvents: (events) => {
// do something with the events
},
});

Listen to specific events for a contract

import { prepareEvent, watchContractEvents } from "thirdweb";
const myEvent = prepareEvent({
event: "event MyEvent(uint256 myArg)",
});
const events = await watchContractEvents({
contract: myContract,
events: [myEvent],
onEvents: (events) => {
// do something with the events
},
});

Parameters

Returns

The unwatch function.