I’m working with the wagmi.sh library for my DApp, and I’ve got a snag with custom nonces.
I’m using the
useSendTransaction hook with a nonce property, but when I reuse a nonce for another transaction, the system doesn’t play nice. It just skips to the next one.
I even tried the
ethers.js library changing the nonce when sending the transaction, but it didn’t solve the issue either.
Any tips on nailing down nonces? Would appreciate your insights!
Hello @giangp !
Welcome to MetaMask community !
Nonce guarantees the order that transactions will occur and must be increased for each transaction. Perhaps the
eth_getTransactionCount ( returns the number of transactions sent from an address.) will be useful to you:
https:// docs. infura .io /networks /ethereum /json-rpc-methods/eth_gettransactioncount
Also, in any parallel execution, you will probably need to require transactions on pending status to avoid collisions leading to errors.
Thanks for your contribution!
Actually I’m using Infura as a provider to get the count of the transactions, using that exact method. But after I use that value in the wagmi hook or in the ethers sendTransaction function it goes to the next nonce.
@giangp Have you tried increasing the nonce value by 1 ?
No, because I want to cancel the transaction through my web app. Not manually with MetaMask. e.g I have a wallet that has a pending transaction and the user presses a button to cancel the transaction, the web app should open MetaMask pop-up with the the nonce of the pending transaction
gm, I came across a post that describes an issue similar to what I’ve experienced.
While developing a dApp designed to cancel pending transactions, I noticed a discrepancy in MetaMask’s UI. There seem to be a few issues surrounding nonce reuse, but I’d like to specifically address one that stands out. I’ve included a screenshot to illustrate the problem:
From the screenshot, you can observe that part of MetaMask’s interface acknowledges the customized nonce (#13) that I’ve set to replace the preceding and still-pending transaction (the warning message is in Spanish). However, at the bottom where the nonce is configured, it doesn’t update to the new nonce value, but rather it suggests the previous nonce+1 (#14, a new nonce!).
This appears to be an oversight; while the top part of the interface accepts and displays the nonce customization, the bottom section doesn’t reflect this change.
Could you please provide guidance? Is there a new method or approach to relay the desired nonce to MetaMask? This is crucial for my dApp to function as intended, especially when canceling or reusing pending transactions.
Thank you for taking the time to review this report. I’m hopeful for a timely resolution to this matter.
The exact same thing is happening to me, the UI shows the selected nonce. But the personalized nonce shows the next nonce and after the transaction is sent, it shows the wrong nonce
Adding some information related to the UI bug related to the nonce substitution, today, I would like to further highlight some challenges we’ve encountered using the MetaMask for Android app.
To succinctly detail the problem:
- Main UI Discrepancies: The custom settings for GAS, PRIORITY FEE, and GAS PRICE aren’t visible in the primary transaction window.
- Secondary Window Reflection: Intriguingly, these customized settings do appear when we access the secondary UI, specifically when clicking on the ETH gas price for adjustments.
- Transaction Inconsistencies: Despite the above point, transactions are sent with a different gas configuration, seemingly ignoring our customized inputs, that are valid.
From a conceptual standpoint, these inconsistencies can potentially mislead users and disrupt smooth transaction experiences. We believe we might be observing integration challenges native to MetaMask.
I’d like to kindly inquire if there are any developers from MetaMask present who could shed light on these observations. My team is genuinely passionate about enhancing the user experience and would be thrilled to assist in rectifying these concerns. For context, we had previously applied for a grant with a proposal to improve transaction dynamics. While it’s unrelated to bug correction, our dedication to refining the ecosystem remains unwavering.
Thank you for your time and consideration. We eagerly await your help, feedback and hope to collaborate soon!
Thanks for the feedback @ariutokintumi!
Would you be able to create a GitHub Issue for this?
Certainly, I’ll submit the issue on GitHub later today and will circle back here to confirm once it’s done.
Thank you for your prompt and considerate response!
I’ve reported the mobile bug; you can view the details in your Github: issues/7163
Additionally, I’ll report the desktop bug concerning nonce substitution tomorrow and will promptly update this thread with the link.
Our project heavily relies on these functionalities. How might we assist or collaborate to expedite the resolution of these issues?
Thank you for your attention to this matter.
The new report for the desktop extension is also completed, you can view the details in your Giuthub: /MetaMask/MetaMask-extension/issues/20784
Again, thank you for your attention to this matter!
Thanks for the detailed description of the problem. @giangp @ariutokintumi
I came across something similar in development some time ago while testing an application on the desktop.
The version of the MetaMask extension that I used is currently outdated.
But the interesting fact is that my problem with the nonce displaying incorrectly was related to the MetaMask extension, and I needed to reset it in order to get the correct current nonce value.
If you haven’t tried
Advanced Setting > Reset Account, can you tell us if there is a change in the behavior of your application after this ?
Even if this doesn’t help, it will probably be useful for detailing the report.
Thank you for sharing your experience and offering a potential solution. We appreciate the effort to assist.
To clarify, our primary issue isn’t with detecting or using the “current nonce value”. Our challenge lies in conveying a customized (yet valid) nonce value, which might differ from the current one. This could be for reasons like:
- Replacing a current pending transaction.
- Specifying a future nonce (which, though it might seem unconventional, is valid and will queue up as soon as preceding nonce transactions enter the mempool).
I understand from your suggestions that you’re addressing a sequence of nonce values, but our concern isn’t precisely aligned with that. We’re exploring a different aspect of nonce customization.
Thank you again for your input; all perspectives help in refining the understanding of the issue.
By using “current nonce value” I meant the value I passed to ether.js as the required nonce. (I was looking at the nonce in the context of a web application) Sorry for misleading you