Add receipt-wait option for hardhat-ethers signer#8249
Open
mmv08 wants to merge 2 commits into
Open
Conversation
🦋 Changeset detectedLatest commit: f2fb897 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
There was a problem hiding this comment.
Pull request overview
Adds an opt-in hardhat-ethers per-network config flag to make HardhatEthersSigner.sendTransaction wait until the transaction receipt is available before resolving, improving reliability for test suites running against external RPC nodes (where eth_sendTransaction may return before mining).
Changes:
- Introduces
networks.<name>.ethers.waitForTransactionReceiptsconfig option (defaultfalse) with validation + resolution into the resolved network config. - Updates
HardhatEthersSigner.sendTransactionto optionallywaitForTransaction(hash)after the transaction becomes queryable by hash. - Adds documentation and tests covering default (no receipt wait) vs configured (receipt wait) behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/hardhat-ethers/test/transactions.ts | Adds tests asserting default pending semantics vs receipt-wait behavior when configured. |
| packages/hardhat-ethers/test/helpers/helpers.ts | Ensures the plugin (and its config hook) is loaded in test HRE initialization. |
| packages/hardhat-ethers/src/type-extensions.ts | Extends Hardhat network config typings with the new ethers.waitForTransactionReceipts option. |
| packages/hardhat-ethers/src/internal/signers/signers.ts | Implements optional receipt-wait behavior in sendTransaction. |
| packages/hardhat-ethers/src/internal/hook-handlers/config.ts | Adds config hook to validate and resolve the new network-scoped option. |
| packages/hardhat-ethers/src/index.ts | Registers the new config hook handler for the plugin. |
| packages/hardhat-ethers/README.md | Documents the new configuration option and its intended use-case. |
| .changeset/hardhat-ethers-wait-for-receipts.md | Declares a patch release for the new option. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
HardhatEthersSigner.sendTransactioncurrently mirrors ethers'JsonRpcSigner: aftereth_sendTransaction, it pollseth_getTransactionByHashand resolves once the transaction is visible to the node. It does not wait for a receipt.That behavior is correct as the default because it preserves ethers-compatible pending-transaction semantics. Some Hardhat tests and user code intentionally rely on receiving a
TransactionResponsebefore the transaction is mined, especially when automining is disabled.At the same time, many existing Hardhat test suites were authored against Hardhat's in-process network, where
eth_sendTransactioneffectively behaves synchronously because the transaction is mined before the call returns. When those suites are pointed at external nodes such as anvil, geth, or reth, a common pattern becomes racy:On external RPC nodes,
eth_sendTransactioncan return after mempool insertion but before mining, so the read may observe pre-transaction state. This makes otherwise useful cross-client or fork-based test runs fail for reasons unrelated to contract behavior.What Changed
This PR adds an opt-in, per-network
hardhat-ethersconfiguration option:When enabled for a network,
HardhatEthersSigner.sendTransactionstill returns the sameTransactionResponse, but only afterprovider.waitForTransaction(hash)has observed a receipt.Why This Is Safe
false, so existing ethers-compatible behavior is unchanged.@nomicfoundation/hardhat-ethers; it does not change Hardhat core or the network manager.provider.waitForTransaction(hash)instead oftransactionResponse.wait(). This is intentional:TransactionResponse.wait()throws forstatus === 0receipts, but callers and chai matchers still need the response so they can inspect reverted transactions themselves.Testing
From
packages/hardhat-ethers:Result:
266 passing,2 skipped.