Getting this error when trying to do concurrent transactions. How to fix it?
(node:64375) UnhandledPromiseRejectionWarning: Error: replacement fee too low (version=4.0.26)
at Object.throwError (.../node_modules/ethers/errors.js:76:17)
at .../node_modules/ethers/providers/json-rpc-provider.js:280:36
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:64375) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:64375) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
To reproduce:
const ethers = require('ethers')
const ethAmount = ethers.utils.parseEther('0.001')
const provider = ethers.getDefaultProvider('rinkeby')
const senderPrivateKey = ...
const tx1 = new Promise(async resolve => {
const recipientAddress = '0x0000000000000000000000000000000000000002'
const wallet = new ethers.Wallet(senderPrivateKey, provider)
const res = await wallet.sendTransaction({
to: recipientAddress,
value: ethAmount
})
return res
await res.wait()
})
const tx2 = new Promise(async resolve => {
let recipientAddress = '0x0000000000000000000000000000000000000001'
const wallet = new ethers.Wallet(senderPrivateKey, provider)
const res = await wallet.sendTransaction({
to: recipientAddress,
value: ethAmount
})
return res
await res.wait()
})
;(async () => {
await Promise.all([tx1, tx2])
}()
If you are sending transactions to the network faster than the network can propagate the “pending” nonce, you will need to manage the job s manually. In v5, I will have a once manager, but for now, you will need to query the nonce (wallet.getTransactionCount()) and specify the nonce in each transaction, incrementing it with each transaction.
Make sense? (Sorry, on my phone so it’s hard to type code; but if you search through issues for NonceManager, you should find some example code)
Closing this now, but please feel free to re-open, or continue discussion (I monitor all closed issues).
Thanks! :)
Most helpful comment
If you are sending transactions to the network faster than the network can propagate the “pending” nonce, you will need to manage the job s manually. In v5, I will have a once manager, but for now, you will need to query the nonce (wallet.getTransactionCount()) and specify the nonce in each transaction, incrementing it with each transaction.
Make sense? (Sorry, on my phone so it’s hard to type code; but if you search through issues for NonceManager, you should find some example code)