ethers.js: Enable EIP- 2831 Signer transaction.wait() style rejections.
When a Signer sends a transaction, the TransactionResponse object has a .wait()
method. Currently that method rejects a CALL_EXCEPTION
if the transaction reverts, otherwise it resolves with the TransactionReceipt, once the transaction is mined, based on its hash.
This feature will enable an additional rejection case, along with a new error in the Logger, TRANSACTION_REPLACED. This will occur if the transaction is replaced (i.e. the from
and nonce
match the transaction but the hash is different), with a field indicating the reason for the replacement:
repriced
; the data and to match, but the gas price has changedcancelled
; the data has been changed to0x
and theto
changed to thefrom
replaced
; any other change
This must occur in a minor version bump.
In v6 we may change repriced
to also resolve (instead of reject), but this requires more thought and would not be backwards compatible within v5.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 19
- Comments: 30 (8 by maintainers)
Commits related to this issue
- Added new error for replaced transactions (#1477). — committed to ethers-io/ethers.js by ricmoo 3 years ago
- Added initial support for detecting replacement transactions (#1477). — committed to ethers-io/ethers.js by ricmoo 3 years ago
- Added new error for replaced transactions (#1477). — committed to shapeshift/ethers.js by ricmoo 3 years ago
- Added initial support for detecting replacement transactions (#1477). — committed to shapeshift/ethers.js by ricmoo 3 years ago
- Added new error for replaced transactions (#1477). — committed to shapeshift/ethers.js by ricmoo 3 years ago
- Added initial support for detecting replacement transactions (#1477). — committed to shapeshift/ethers.js by ricmoo 3 years ago
This is now available in 5.2.0. Please check out this article for more details. ๐
Sorry Iโm a bit confused, my case is when I donโt have access to the transactionResponse object but only the hash.
So Iโm waiting on the transaction via the provider, say
In this case, replaceable param is always passed down to _waitFortransaction() as null
tried TRANSACTION_REPLACED, it generated error params as stated in ethers.js enum ErrorCode
There are bunch of other codes like UNPREDICTABLE_GAS_LIMIT, which are well defined in the ErrorCode.
@aysuio, not sure if you found an answer to it, but generally I was using template code from this update: https://blog.ricmoo.com/highlights-ethers-js-may-2021-2826e858277d
Let me know if you managed to test this feature on your end. ๐ I still cannot get it to work because I cannot test it.
If you use a private node, then you should be able to send an intentionally underpriced transaction and it would be detected alright. If you use a public rpc, you need to be fast and get lucky.
Yes, all in all itโs working. Not working only in the case of:
There are definitely problems with both Polygon and BSC when it comes to receipts, that are still being tracked down; they seem to emit data before they complete indexing (and therefore responding to requests).
So, the
result.transactionHash != tx.hash
? Are either left undefined? Do the nonce and from match?