Reducing number of requests for eth_getBlockByNumber and eth_BlockNumber when using HDWalletProvider

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:

  1. 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');


const HDWalletProvider = require("@truffle/hdwallet-provider");

If that doesn’t help, see pollingInterval param that you can use to control it:

  1. 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(`<INFURA_PROJECT_ID>`));
  1. Similar posts regarding the same issue: