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
},
});
function watchContractEvents(options: {
contract: Readonly<ContractOptions<abi>>;
events?: abiEvents;
latestBlockNumber?: bigint;
onEvents: (
events: ParseEventLogsResult<abiEvents, TStrict>,
) => void;
strict?: TStrict;
}): () => void;

Parameters

The options for retrieving contract events.

Type

let options: {
contract: Readonly<ContractOptions<abi>>;
events?: abiEvents;
latestBlockNumber?: bigint;
onEvents: (
events: ParseEventLogsResult<abiEvents, TStrict>,
) => void;
strict?: TStrict;
};

Returns

let returnType: () => void;

The unwatch function.