Increased mining flexibility in Hardhat Network

A realistic network for more elaborate scenarios and better dapp testing

Increased mining flexibility in Hardhat Network

A realistic network for more elaborate scenarios and better dapp testing

The 2.1.0 release of Hardhat Network now includes a full mempool implementation that mimics geth behavior.

The previous automine mode is still available and remains the default, so for those users who are happy with their current setup nothing will change.

For those who are testing dapps, backend services, or more elaborate scenarios that require multiple transactions per block, the interval mining mode can be enabled.

The interval can be set through the config to be fixed or random within a specified range. Additionally, both mining modes can now be fully disabled for block mining to be controlled programmatically. This creates a lot of flexibility for testing, allowing for different tests to use different mining modes as needed.

The mempool behavior mimics geth. This means:

  • Transactions are sorted by gas price, and as many as possible are included per block.
  • When there’s a tie in gas price, transactions are included on a FIFO basis.
  • If a transaction becomes invalid (e.g. because the block gas limit changed), it’s dropped from the mempool.

This has been in the making for a while, and while it’s ready, it remains a beta feature for now. It’ll graduate to stable in a future release. The automine code is stable, so we don’t expect issues for those sticking with the usual mining behavior.

In the future, we’ll add a fluctuating gas price minimum to help test gas management strategies.

You can learn more about this feature in the Hardhat Network documentation.