Can't catch all the events. Why?

I try to listen to events for several contracts and it is ok. But the more contracts I listen to, the more events are missed? Is there any way to prevent this and why event listening does not work correctly when I want to listen to, for example, 100 contracts at once. Are there any guidelines how to do it correctly ?

Such a trivial question. Maybe I should just listen to one contract for each file, only it seems a bit punitive....

My code looks like most tutorials and so it starts like this:

const contract = new ethers.Contract(contract,  abi , provider )
    //  contract.on("Transfer", async (from, to, value, event, error) => {  

I tried both ethers js and web3. In both cases, when I listen to more events in one file, more often the event is not recorded, and I want to make sure that it captures 100% of the events

1 Answer 1


When I have needed to listen to events in the past, I don’t need to instantiate the contract each time like this.

To be clear, im not sure why the method you’re using doesn’t work consistently - perhaps you could post some code to help us get through this.

Usually I would use Alchemy or Infura to open a web socket or use web3.eth.abi.decodeParameters() and pass the necessary types array needed to decode the event topic handlers. The code might look something like this in JS:

typesArray = 
    type: 'address',
    name: 'addressFromTopic',
    indexed: true

for (log of logs) {   
   try {
let logData = {
address: web3.eth.abi.decodeParameters(topicArray,String(log.topics[1]);
}  catch { error }};

…for instance if you were trying to decode the first topic (perhaps the event emit from the contract) of the transaction on chain. This will give 100% yield as long as you define your to address properly in the decodeParameters() call, and any failed log reads can be noted and re-run in the catch block (yes, server timeout errors et al are quite common)

Hope that helps 🙌

  • Can I do the same thing using ANKR ? I still don't know what I am doing wrong . I tried web3 but I'm better off with ethers js - I think the problem is that I'm using the for each function and there's just too much of it in one file - but why?? items.forEach(function(name) { const contract = new ethers.Contract(name.contract, name.abi , name.provider ) // contract.on("Transfer", async (from, to, value, event, error) => { contract.on("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", async (from, to, value, event, error) => {
    – byggy
    May 15 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.