eth_getBlockByNumber request call are so high

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.

Hi, @vanijatko.social,

What do you use instead of HDWalletProvider ?

I cant get truffle to complete migration ever… getBlockByNumber uses up all limits I have…

Thanks!

Hi everyone,
I was experiencing the same problem when using Truffle HD Wallet provider. After some troubleshooting, I realised that the object returned from the wallet provider has a property called _pollingInterval which determines the interval to poll the state of the blockchain (this is what uses up so many requests).

This value can be manually adjusted to something like 1800000 (30 minutes) with the following code before passing the provider object into web3:
provider.engine._blockTracker._pollingInterval = 1800000;
Where provider is the object returned by Truffle HD Wallet provider when creating an instance of it. This seems to have no negative impact on interacting with the blockchain and dramatically reduces the requests to Infura. Hope this helps.

3 Likes

very useful info and resolved my issue. thank you

2 Likes

Hello TheAndrei
i have the same issue but when i added it to the truffle-config i still get 1000s of requests Screenshot - 9fd8a36f5ac27cc685a2422aae29f90e - Gyazo
how/where am i adding
provider.engine._blockTracker._pollingInterval = 1800000; ??