ContractEvents.addEventListener() method
Subscribe to contract events
Example
contract.events.addEventListener("TokensMinted", (event) => {
console.log(event);
});
Signature:
addEventListener(eventName: keyof TContract["filters"] | (string & {}), listener: (event: Record<string, any>) => void): () => void;
Parameters
Parameter | Type | Description |
---|---|---|
eventName | keyof TContract["filters"] | (string & {}) | the event name as defined in the contract |
listener | (event: Record<string, any>) => void | the callback function that will be called on every new event |
Returns:
() => void
a function to un-subscribe from the event
Remarks
You can add a listener for any contract event to run a function when the event is emitted. For example, if you wanted to listen for a "TokensMinted" event, you could do the following: