I made a transaction on uniswap, with code like:

const provider = ethers.getDefaultProvider('mainnet', {
    infura: INFURA_ID

const signer = new ethers.Wallet(MY_WALLET_PRIVATE_KEY)
const account = signer.connect(provider)
const uniswap = new ethers.Contract(

const tx = await uniswap.swapExactTokensForTokens(
        gasLimit: 1000000,
        gasPrice: ethers.utils.parseUnits("30", "gwei") 

const receipt = await tx.wait()

It has been 5 hours, it's still pending. The transaction: https://etherscan.io/tx/0x6208c9e981bdb8bb0dde1816550c0b0f046977d83d2a55e3aba178977cc05cd0

I cannot do further transaction, it says There is a Pending txn with a lower account nonce. This txn can only be executed after confirmation of the earlier Txn Hash#

I found some topic says use a "nonce" to cancel a transaction, but I don't find any "nonce" on etherscan page.

How to terminate the transaction?

  • you need to wait 3 hours without sending anything and it will expire
    – Nulik
    Jul 15, 2021 at 20:26
  • or send a replacement transaction with 0 value to yourself with 10% higher gas price
    – Nulik
    Jul 15, 2021 at 20:27
  • expired finally Jul 15, 2021 at 21:13

1 Answer 1


In the future, if you wanted to cancel a pending transaction you need to frontrun your own transaction by posting some other transaction with the same nonce. It can be the same transaction, or it can be a different, unrelated transaction. The important thing is that you need to use the same nonce, but a higher gas price. The idea is that by posting a more expensive transaction, the nodes will choose it instead of the original transaction (and they have to choose, because the nonce cannot be duplicated).

All assuming that the original transaction was not mined yet, but is still pending to be mined.

You can find the nonce in the transaction you posted. It's visible when you click on the "Click to see more" link. It is just above the "input data" section (see the picture below). It's 7.

Screenshot of transaction details with highlighted nonce property

If you wanted to create an "updated" call to the uniswap contract, you should've just added the nonce: 7 override to your uniswap.swapExactTokensForTokens call.

If instead you wanted to "undo" the uniswap method call (and not replace it), you should've cancelled the transaction by posting an "empty" transaction. Something like await wallet.provider.call({to:"0x0", value: 0, nonce: 7, gasPrice: 60}); (sending 0 ETH to receiver address: 0x0).

Be aware that cancelling/replacing a pending transaction costs ETH, because you actually need to post something on the blockchain!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.