Skip to main content

Contract Events

You can listen to events that are emitted by a contract.

This is useful when you want real-time updates of events happening on the blockchain.

The names of the events are the same as the events emitted from the smart contract.

For pre-built contracts, you can inspect the source code to see the events that are emitted in each function call.

Below are some examples:

Event NameDescriptionSource Code
TokensClaimedToken claimed by a wallet from a Drop contractSmart Contract Code
TokensMintedToken minted by a wallet into a NFT / Token contractSmart Contract Code
ListingAddedNew listing created in a marketplace contractSmart Contract Code

Listen to All Events

Listen to all events emitted by the contract.

contract.events.listenToAllEvents((event) => {
console.log(event.eventName) // the name of the emitted event
console.log(event.data) // event payload
}

Listen to a Specific Event

Listen to all occurrences of a specific event.

contract.events.addEventListener("TokensMinted", (event) => {
console.log(event);
});

Listen to Transactions

Listen to all transactions in their raw form.

contract.events.addTransactionListener((event) => {
console.log(event);
}

Remove All Listeners

contract.events.removeAllListeners();

Remove an Event Listener

contract.events.removeEventListener("TokensMinted", (event) => {
console.log(event);
});

Remove a Transaction Listener

contract.events.removeTransactionListener((event) => {
console.log(event);
}