Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Events matching a filter are fired by the square of the number of filters #404
Ok, found some weird behaviour that may need an explanation, or is a bug.
When I listen for an event in multiple places, i.e.:
const contract = new ethers.Contract(...etc, ethersProvider) var filter = contract.filters.TestEvent() ethersProvider.on(filter, console.log) // listen in one place ethersProvider.on(filter, console.log) // listen in another place
When the smart contract emits a TestEvent, the above code prints out the event four times.
If I added a third
I think I have an explanation:
Now, this would explain the (event listeners)^2 results I was getting above, because:
Tested the latest code- the fix works for
My test was:
const filter = contract.filters.Test() provider.on(filter, console.log) provider.on(filter, console.log)
I then transacted with Ganache for one event and there was two console.logs. Correct!
However, this test:
const filter = contract.filters.Test() contract.on(filter, console.log) contract.on(filter, console.log)
The above test still prints four console.logs, so for some reason the contract specific one is still not working.