eth_getBlockByNumber request call are so high

Hello,
Greetings!!

We are using web3 ETH API in our project. we are normally calling api when we want to write data.
we are using functions ( Web3.eth.estimateGas, Web3.eth.getTransactionCount, Web3.eth.getTransaction, Web3.eth.getTransactionReceipt )
were Web3 is var Web3 = new web3(new web3.providers.HttpProvider(config.rinkebyInfuraUrl));

We are NOT using “eth_getBlockByNumber” this method at all in our project.
Our daily request count exceeds the limit. ( with no more user using daily, say only 2-3)
It just when we call Web3.eth.getTransaction for getting details by transaction hash, then also the request for eth_getBlockByNumber is called so high.

Is there any log to be enabled to see when or where eth_getBlockByNumber requests are called?

Any help will be appreciated !!
Thanks
Swapnil M

Hi @Swapnil_Marathe - welcome to the Infura community! Can you share the code generating that request so we can see if we can help you identify what’s going on?

I am having the same issue using webpy and eventeum. I think the issue may be eventeum polling for the information in each block?

Hi @Leiya_Kenney,thanks for your reply.
here is sample code which we use for getting meta-data information by transaction hash.
then also eth_getBlockByNumber method calls are so high.

var web3 = require(‘web3’);
var Web3 = new web3(new web3.providers.HttpProvider(https://rinkeby.infura.io/v3/<project_id)>;
Web3.eth.getTransaction(transactionHash, function(err, response) {
if (err != null) {
var errorJsonResponse = {
“Error”: err.message
}
callback(errorJsonResponse);
} else {
callback(null, response);
}
});

we have a “developer” plan enabled for infura, also I can DM you email associated with infura account so you can look in from your end.
Please provide your thoughts on this, if any code changes or any logs of eth_getBlockByNumber we can get.

Thanks!!

Hi @Swapnil_Marathe,

Have you tried swapping your key, just to make sure it’s not being used by someone else? Alternatively, have you tried using WebSockets instead of HTTP? This may bring down background polling, thereby bringing down the number of eth_getBlockByNumber calls.

@michaelmoe94 - you’re absolutely correct. Sometimes there will be polling in the background; ethers.js definitely does it, and eventeum likely does something similar.

Hi @Leiya_Kenney Thanks for reply,

are you suggesting to change this above code.

var Web3 = new web3(new web3.providers.HttpProvider(https://rinkeby.infura.io/v3/<Project_ID>));

to following code.

let web3 = new Web3(
// Replace YOUR-PROJECT-ID with a Project ID from your Infura Dashboard
new Web3.providers.WebsocketProvider(“wss://mainnet.infura.io/ws/v3/YOUR-PROJECT-ID”)
);

Trying above giving me error as

web3.providers.WebsocketProvider is not a constructor
My npm web3 version is “0.20.7”

Do change this code will affect my all API?
Have you tried swapping your key,
Can you tell me which key?? ( is this key is Project ID ?)

According to this thread, it looks like you may need to update your Web3.js so that it’s above 1.0.

As far as the key, yes - apologies - the key is the Project ID. I would suggest swapping that out to see if that changes things.

Hi @Leiya_Kenney thanks for reply,
yes i have tried swapping Project ID, we were using free account first, but now we have taken “developer” plan ( 2lahk request per day ). But no luck with using new Project Id. Request are so high

Can you send over the full code (not just the snippet above) so we can see where you can potentially make some optimizations?

@Leiya_Kenney I will DM you. Can you send me your email id or something where i can connect to you via DM.
Thanks

If you click on my name, you should be able to see an option to message me privately!

HI, im not able to send message to you privately.

Is That resolved? I am also getting so many eth_getBlockByNumber it’s like 67% of total usage.

@Leiya_Kenney Does subscribing to events with wss also increase the eth_getBlockByNumber ??

same here!

@sacgrover and @jmonteer - we’re still working to figure it out. Are you using web3-provider-engine by any chance? If not, can you please provide a code snippet of the code with the high eth_getBlockByNumber calls?

No I am not using web3-provider-engine. Here is my code snippet:

 	const today = new Date(); 
	filterDate.push(today.toISOString().slice(0,10).replace(/-/g,""));
	const yesterday = new Date(today);
	yesterday.setDate(yesterday.getDate() - 5); 
	filterDate.push(yesterday.toISOString().slice(0,10).replace(/-/g,""));

	this.marketPlace.getPastEvents('BetWinner', {
	  filter:{date: filterDate},
	  fromBlock: 0,
	  toBlock: 'latest'
  }, (error, events)=>{ console.log(events); })
  .then((events)=>{
	if(events){
	  events.forEach(ev => {
		let price = this.web3Service.convertEtherToPrice(ev.returnValues.price);
		this.winners.push({ id:ev.returnValues.id,coin:ev.returnValues.coinSide,address:ev.returnValues.winner,price:price*2 });
		sessionStorage.setItem("winners", JSON.stringify(this.winners));
	  });
	}
  });

I am using truffle and truffle/hdwallet-provider, which I believe uses web3-provider-engine. What is your proposed alternative? Thanks!

@jmonteer - try giving this library a try - it’s more actively maintained than the web3-provider-engine you’re currently using, so will likely have fewer errors: https://www.npmjs.com/package/eth-json-rpc-infura

@sacgrover - I’m looking into your code to see where the high volume of getBlockByNumber calls are coming from and will let you know what I can find.

Hi everyone,
Same issue here. Enormous requests were sent just in 1 hour of testing - eth_getBlockByNumber
2,452. Looking forward hearing about the potential reason

UPD: figured out, the issue was with HDWalletProvider. Just stopped using it and all is fine. Perhaps it uses web3 subproviders and they do smt strange…

1 Like

Hi @vanijatko.social - welcome to the Infura community! Glad you figured out what was causing your high number of requests.