If you’re using Truffle’s HDWalletProvider and seeing big numbers of requests made by eth_getBlockByNumber or/and eth_BlockNumber most likely this is coming from HDWalletProvider which does constant block polling.
Some suggestions below:
- truffle-hdwallet-provider is deprecated, try to use the current one which might be better at block polling.
In most cases it should be enough to replace:
const HDWalletProvider = require('truffle-hdwallet-provider');
with
const HDWalletProvider = require("@truffle/hdwallet-provider");
If that doesn’t help, see pollingInterval param that you can use to control it:
https://github.com/trufflesuite/truffle/tree/develop/packages/hdwallet-provider
- Use HDWalletProvider only where needed, eg. deploying or calling contract methods. For anything else (like sending tx) you can use either a Websocket or HTTP provider, example for HTTP:
const web3 = new Web3(new Web3.providers.HttpProvider(`https://rinkeby.infura.io/v3/<INFURA_PROJECT_ID>`));
- Similar posts regarding the same issue:
https://infura.discoursehosting.net/t/eth-getblockbynumber-request-call-are-so-high/1871
https://stackoverflow.com/questions/64861707/infura-calls-eth-getblockbynumber-ten-times-for-each-eth-call