Marcelo Urquiza
Marcelo Urquiza

Reputation: 23

where can I find a list of events supported by contract event listeners in Ethers.js - Swap Event Listeners?

I am studying a code that uses ethers.js to listen to Ethereum blockchain events and triggers a series of tasks when a swap occurs in the blockchain. The part of the code that listens for the event is below.

uPair.on('Swap', async () => {
    if (!isExecuting) {
        isExecuting = true

I already understood how the event listener works, but did not understand why the event name for a swap event is Swap.

The documentation at https://docs.ethers.org/v5/api/contract/contract/#Contract-on only tells me the format of the on() method:

contract.on( event, listener ) ⇒ this Subscribe to an event calling listener when the event occurs.

I did not find a declaration/definition of Swap anywhere in the code so I imagine the events are already defined by ethers.js or even Ethereum. There is a list of supported events with their corresponding strings somewhere, but I was not able to find it.

I don't even know what to try since I do not see what other event names are supported.

Upvotes: 0

Views: 440

Answers (1)

Robin Thomas
Robin Thomas

Reputation: 4146

The Contract.on method allows you to listen for events from a smart contract (which you have already understand).

The event names used for Contract.on depends on the events that are declared and emitted within the smart contract.

That means, a smart contract developer can create an event, by writing the below in solidity:

event <eventName>(arguments);

This event can be then "emitted" within a transaction using:

emit <eventName>(arguments);

Which is why you won't find a list of events supported, because anyone can create events with different names.

Upvotes: 0

Related Questions