Comments (14)
Wrap your signer in a NonceManager to ensure sequential nonces for concurrent transactions
import { NonceManager, Signer } from 'ethers'
const signer: Signer = NonceManger(wallet);
from ethers.js.
I got error "ProviderError: Nonce too low. Expected nonce to be 1 but got 0" when in a local hardhat node I tried to send a raw transaction that has been signed by some other account and whose nonce is 0.
I had to fund that account first (to prevent "insufficient funds error"), then send the raw transaction:
let txRec = await signer.sendTransaction({ to: otherAddress, value: ethers.parseUnits("0.1", "ether") })
await txRec.wait()
const signedRawTx = "0x..."
const txHash = await ethers.provider.send("eth_sendRawTransaction", [ signedRawTx ])
from ethers.js.
How is the signer
object created? Is the signer connected to the node provider? You can use signer.connect(provider)
or provider.getSigner(addr)
to have a signer with provider.
This enables the signer to infer the nonce otherwise it will use zero as the nonce while preparing the transaction.
from ethers.js.
How is the signer object created? Is the signer connected to the node provider? You can use signer.connect(provider) or provider.getSigner(addr) to have a signer with provider.
This enables the signer to infer the nonce otherwise it will use zero as the nonce while preparing the transaction.
Thanks for your reply. The signer is connected to a provider
from ethers.js.
I got error "ProviderError: Nonce too low. Expected nonce to be 1 but got 0" when in a local hardhat node I tried to send a raw transaction that has been signed by some other account and whose nonce is 0.
Thanks for your reply. In my case, one signer is used (not multiple).
https://github.com/claasahl/ethers-v6-with-hardhat/blob/main/src/example1.ts
from ethers.js.
That did the trick. Thanks @applewil
from ethers.js.
Wrap your signer in a NonceManager to ensure sequential nonces for concurrent transactions
import { NonceManager, Signer } from 'ethers' const signer: Signer = NonceManger(wallet);
NonceManager not stable
from ethers.js.
@Aziz87 Does it mean that it's not good to use it in deployment script for main net?
from ethers.js.
What do you mean NonceManager is not stable? The nonce is managed internally, so there shouldn't be any problems regarding nonce management.
from ethers.js.
we've recently been upgrading from ethers v5 to v6 (finally), and we're hitting these issues too. What has changed from v5 to v6 related to nonce management..? its a bit strange we even need to wrap the wallet with a NonceManager .. doesn't feel like the cleanest approach or DX
from ethers.js.
@pkieltyka Nothing should have changed in ethers. In both v5 and v6, the getTransactionCount(address, "pending")
is used.
Or are you using the NonceManager? I still donโt think anything in the NonceManager (behaviour-wise) should have changed though.
Are there other libraries that could have affected behaviour in some way, like Hardhat?
from ethers.js.
I'm not working on the upgrade first hand myself, but my engineering team let me know they've been hitting the problem and then as I read the thread with suggestion to use the NonceManager to wrap the wallet, that looked very strange/unnecessary. But we'll definitely report back with our findings, and yea perhaps its something with hardhat.
Glad to hear between v5 and v6 its the same getTransactionCount(address, "pending")
from ethers.js.
Yeah, both Wallet and NonceManager should behave identically between v5 and v6. But I think Hardhat did a bunch of new things?
Regardless, have any engineer reach out to me on GitHub or Discord. I usually respond immediately to Discord assuming Iโm awake, and catch up once awake if Iโm asleep. :)
from ethers.js.
btw, you're right... I just tried to instead of using hardhat provider inline in the tests, I setup a JsonRpcProvider and pointed it at http://localhost:8545, running anvil .. and tests passed! the nonce has already been used
issue has gone away
strange.. we're using the latest version of hardhat too, maybe something weird with the config there.. I'll investigate as I'm sure hardhat should work just fine too.
thanks very much for the offer to help and being so quick to respond! hope you're well buddy!!
from ethers.js.
Related Issues (20)
- Await on Transaction Submission Waits for Confirmation HOT 11
- Missing r argument after submit transaction in metamask HOT 2
- deployTransaction property is undefined after contract deployment HOT 1
- estimateGas does not support eip-4844. HOT 4
- Tuple return values from contract calls cannot be used as parameters in subsequent calls. HOT 1
- ProviderError: the method has been deprecated: eth_accounts
- mnemonic.computeSeed is not a function (hdwallet.js:318:48) HOT 3
- Error: invalid value for value.data HOT 1
- Unsigned ethers v6 type 2 transaction HOT 4
- Incorrect EIP712 hashed data with array type
- unknown fragment HOT 1
- Expose encodeFunctionData and decodeFunctionResult as properties on the contract method HOT 1
- Property 'utils' does not exist on type 'typeof
- After the network is switched, the latest provider cannot be obtained HOT 2
- returns code BAD_DATA instead of INSUFFICIENT_FUNDS HOT 1
- Should return code TIMEOUT instead of UNKNOWN_ERROR HOT 1
- 'contract runner does not support calling' error HOT 1
- Not able to resolve module `@adraffy/ens-normalize`
- could not detect network (event="noNetwork", code=NETWORK_ERROR, version=providers/5.7.2)
- QuickNodeProvider does not work HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ethers.js.