The behavior you're experiencing occurs because you've disabled auto-mining. In a Hardhat environment with auto-mining disabled (i.e. evm_setAutomine
set to false
), transactions get queued and are not automatically mined in new blocks. As a result, await initTx.wait();
hangs because it's waiting for the transaction to be included in a block, and for a receipt to be generated.
To resolve this, you need to manually mine a block after sending the transaction. You can do this using the evm_mine method as follows:
// Send the transaction
const fooTx = await myContract.foo();
// Manually mine the block to include the transaction
await network.provider.send("evm_mine");
// alternatively do "await mine();"
// mine is a wrapper around evm_mine and can be imported from "@nomicfoundation/hardhat-network-helpers"
// Now this won't hang as the transaction has been mined
const fooRc = await fooTx.wait();
This approach allows you to include multiple transactions in the same block by sending multiple transactions before calling evm_mine
. It gives you precise control over transaction ordering within a block provided you've configured "fifo"
transaction ordering for your hardhat node.