Curious how does eth_getLogs, eth_blockNumber, get_chainId works?

We have an app that we’re using Infura to provide blockchain connection. However, the usage is currently getting maxed out every day. I only use a free account so it’s around 100k per day.

I’m using the JsonRpcProvider for the connection to Infura.

I tried to comment on a function that listens to the contract. For example,

// Assumed it's Mumbai, goerli, ether and polygon on rpc provider
const provider = new ethers.provider.JsonRpcProvider(rpc_url);
const instance = new ethers.Contract(contract.address, contract.abi, provider);

instance.on('ItemListed', (...args) => {
  console.log('item listed');
  // handleItemListed();
});
// more than 3 events

then I tested it out, nothing shows on the log but there’s still a number of eth_getLogs and eth_blockNumber showing on the Infura dashboard

The number of requests should be around 0, not more than 100k.

Can someone explain what’s happening? How do the eth_getLogs, get_blockNumber, get_chainId count the requests even if the event listeners didn’t use them?

Hi @jclumacad_1, can you provide your account email and project ID so I can check some stats? You can open a case here if you prefer.

Warm regards,
Chris | Infura | ConsenSys

Summary

This text will be hidden

Hey @jclumacad_1 can you try with InfuraProvider instead of the JsonRpcProvider. See this thread for reference eth_chainId is called every time the provider is used · Issue #901 · ethers-io/ethers.js · GitHub.

Hey @traian.vila . I tried using InfuraProvider but the requests increases every second on eth_getLogs and get_blockNumber even if there’s no incoming data from the event listeners

Also, I’m using ethers@^5.6.8

Right now, the requests for today is 63k+ and then I received 8 transactions coming from the etherscan but all of them are coming from Rinkeby. There’s no transaction yet for Mumbai. Not sure why the number of requests was so high.

Method request volumes:
Sept 27, 8-11AM UTC
eth_getLog = 23,524
eth_blockNumber = 37,509
eth_chainId = 0

Network request volumes:
Sept 27, 8-11AM UTC
polygon-mumbai = 22,046
rinkeby = 38,987

This time I used InfuraProvider not JsonRpcProvider

Can someone explain why this is happening?

Also, how do you calculate the requests today? Is it by the sum of the Method request volumes or Network request volumes?

Same with StaticJsonRpcProvider, it still increases @chris.paterson

I just found out that using WebSocketProvider will solve the problem of the usage of network requests.
It doesn’t work on InfuraProvider, JsonRpcProvider and StaticJsonRpcProvider