There is a piece of code in the issue, but here is a little more complete example:
const provider = new Web3.providers.WebsocketProvider(process.env.INFURA_WS);
const web3 = new Web3(provider);
web3.eth.handleRevert = true;
const subscribe_to_contract_events = async contract => {
contract.events.SomeEventName().on("data", async event => {
// process the event
});
}
for (const contract of contracts) {
try {
await subscribe_to_contract_events(contract);
} catch (err) {
console.error(err);
}
}
Where the contracts
is an array of contracts, created by
new web3.eth.Contract(abi, address);
The array contains around 400 elements, so I subscribe 400 times.
Is this something to do with the many subscriptions? It’s very sporadic, but my guess was that it’s caused if many events are happening at the same time.