Usage consumed by eth_getLogs and eth_getBlockNumber calls

We have a tiny app that we’re using Infura to provide occasional blockchain connection to. However, the usage is currently getting completely maxed out every day. The number of daily transactions at the moment is around 100,000 (62k so far today) but it should really be around… zero.

The transactions occurring are about 70% eth_getLogs and about 30% eth_getBlockNumber calls. I don’t know why they’re being made. Our application isn’t currently even active.

We DO have some websockets connections watching for events, but to hit those kinds of numbers on the eight contracts deployed, the eth_getLogs calls would have to be triggering approximately every 5 seconds. I don’t really understand why that would happen.

Can anyone clarify this?

hi @MattCivicLedger, what library are you using ? It would help to see that code part.

We’re using the EthersJS library to connect. The code is basically this:

const connectionDetails = { projectId: Env.get('INFURA_ID'), projectSecret: Env.get('INFURA_SECRET')}
const provider = new ethers.providers.InfuraProvider( 'goerli' , connectionDetails);

const instance = new ethers.Contract(contract.address, contract.abi, provider);

instance.on('OrderAdded', handleOrderAdded);
instance.on('OrderDeleted', handleOrderDeleted);
instance.on('OrderAccepted', handleOrderAccepted);

// there are 6 more

The only thing I can assume is that the problem is i’m using an InfuraProvider, rather than a WebSocketProvider. Thoughts?

Yup, the method you’re using relies on filters, each filter would call eth_getLogs every time the block changes, see:

We have a PR submitted on ether.js that should make it more efficient and controllable through getFilterChanges, it doesn’t look to be done yet:

Indeed, a better option here is to use the ws subscriptions.