Multiple listeners to each individual array of events or one listener to multiple events

Viewed 13

I currently need to listen to multiple events on the blockchain, and I'm using Ethers to do so, but I also tested using Alchemy websocket, and I'm kinda puzzled about what approach I should take on this. Should I input the multiple events on one listener or create one listener to each event? as far as I've tested, one listener to each event makes multiple eth_logs calls, which makes sense since they are listening to multiple topics, but one listener to multiple topics makes one call and is triggered whenever they occour. I just want to know if multiple listeners makes some huge impact on the cost or doesn't make any significant difference, the main pro that I've noticed, is that I can make multiple handlers to each event separately which is handy but I'm concerned on the impact of this.

examples:

const event1 = "event1";
const event2 = "event2";
const topics = [[event1, event2]];
const address = "address";
const arrayEvents = [event1, event2];

provider.on({ address, topics }, handler);
// vs
arrayEvents.forEach((event) => {
  provider.on({ address, event }, handler);
});
0 Answers
Related