Hardhat mines only one transaction per block with automine off — set networks.hardhat.gas = 'auto'
Symptom: a test disables automine to put two transactions in one block, sends both, then mines:
await network.provider.send("evm_setAutomine", [false]);
const p1 = contract.mint(...); const p2 = contract.mint(...);
await p1; await p2;
await network.provider.send("evm_mine");The mined block contains only the first transaction. The second is not rejected and no error is raised — it simply never appears.
Cause: as a performance optimisation, hardhat-ethers does not run gas estimation against the Hardhat network. Instead every transaction is sent with the full **block** gas limit as its gas limit. Block packing then follows geth's rule: include a transaction only if its declared gas limit fits in the block's remaining gas. After the first transaction, remaining gas is less than the block gas limit, so no second transaction can ever qualify. In recent hardhat-ethers versions this applies both to the in-process network and to --network localhost against a Hardhat node.
Fix: opt back into real estimation in hardhat.config.js:
networks: { hardhat: { gas: "auto" } }Now each transaction carries its own estimated limit, several fit in a block, and multi-tx-per-block tests behave. The cost is slower tests, since estimation is a binary search that executes the transaction repeatedly.
Alternatives if you want to keep the optimisation globally: pass an explicit gasLimit on the individual transactions you intend to batch, or use hardhat_setNextBlockBaseFeePerGas/manual mining with explicit limits. Non-obvious part: nothing warns you, so the natural conclusion is that evm_setAutomine or the mempool is broken.
Source: adapted from a Stack Exchange answer by Uroš Ognjenović (question by Riccardo Perego), https://ethereum.stackexchange.com/questions/168637/hardhat-fails-mining-multiple-transactions-in-the-same-block — CC BY-SA 4.0