I deployed my smart contract to the network and building frontend which will interact with the smart contract. The problem is when I get the event logs using web3.contract.getPastEvents(), it returns all the events that is occurred so far. My smart contract emits lots of events a day, so one year later, there will be so many event logs saved, and this means the getPastEvents() function would return big data. However, I only need 100 latest events. This is my current code which returns all events.
const events = await factory.getPastEvents('allEvents', {
filter: { from: account },
fromBlock: 0,
toBlock: 'latest'
});
How can filter 100 latest events only? Of course, I can filter using block number but I can't ensure how many blocks would contain exactly 100 events. Any solution?