简体   繁体   中英

Ethers.js : "NONCE EXPIRED" when replacing transaction

I am having this issue when I try to replace a transaction with the same nonce, and higher gas fees. For exemple I use a swap function from a DEX:

const tx1 = await contract.swapExactTokensForTokens( amountIn, amountOutMin, [TokenIn, TokenOut], AddressTo, deadline, {'gasPrice': gasPrice, 'gasLimit': gasLimit})

and then I try to replace the transaction with tx1's nonce:

const tx2 = await contract.swapExactTokensForTokens( amountIn, amountOutMin, [TokenIn, TokenOut], AddressTo, deadline, {'gasPrice': gasPrice+1*10**9, 'gasLimit': gasLimit, 'nonce': tx1.nonce})

After this, I instantly get the nonce_expired error. How can I proceed?

probably, your slippage was too tight, try to set higher amountOutMin. For nonce, you should use web3.utils.toHex(txCount) where txCount is web3.eth.getTransactionCount

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM