How to cancel or replace a pending Ethereum transaction?

Tiempo de lectura: 5 minutos

Whoever has never made a mistake when sending a transaction on a blockchain, let him cast the first stone… Probably no stone will be thrown, which indicates how important it is to know how to cancel or replace a pending Ethereum transaction.

In this article, I will go over the methods to carry out this action, but it is also an opportunity, which I will not miss, to explain what are and how transactions in Ethereum work.

So, let’s abandon the preambles and get into the action.

Is it possible to cancel or replace a pending Ethereum transaction?

The question contains, in itself, the key to this entire article. Yes, it is possible to replace or cancel a transaction in Ethereum, as long as the transaction is pending. Once a transaction is confirmed, this means that it was included in a block on the network and its modification will be impossible.

Each transaction we make on the network contains a unique and unrepeatable number, related to our address on the blockchain or, in other words, to our wallet. This number, called “Nonce“, can be modified manually to cancel or replace a transaction on the network.

But, perhaps this beginning gives too much knowledge for known. Therefore, it is necessary to take a step back and prior to knowing the method that we must put into practice, it is necessary for me to elaborate on the transactions, per se, on the Ethereum network.

What is it and how does an Ethereum transaction work?

When we talk about transactions in Ethereum, we are talking about nothing more than interacting with this blockchain. Within the network, there are two types of transactions:

  • Regular or customary transactions
  • Contract implementation transactions

In this article we will focus on the first type. Just to mention them, the second ones are those transactions that those who wish to create an application on the network carry out to “immortalize” their “smart contracts” in the blockchain.

Regular transactions have both a sender and a recipient, and that is their main difference with the former. These can represent a sending from the wallet of one person to another or a deposit in an application, among other examples.

Now, let’s learn a little about the life of a transaction.

What happens from shipment to confirmation of a transaction?

When we send a transaction from our wallet, it travels to a place called “mempool”. This sort of crypto purgatory is where transactions wait to be selected by a miner to be included in a block.

Once the transaction is added to a block and the miner, after managing to solve the corresponding mathematical problem, manages to add the block to the network, it only remains to wait for confirmation. In simple words, this confirmation is a certain number of blocks added to the blockchain, which guarantee that the transactions contained in the previous blocks are valid and immutable.

So, now let’s learn about the different states that transactions go through during their “cryptohistory”.

What statuses can transactions have in Ethereum?

If we check the status of a transaction, after sending it, we will see that it is “unknown“. This means that it has not yet been “seen” or “checked” by a node, which will take it to the famous and, at the same time, scary “mempool”.

Once this happens and our transaction is in the mempool waiting for a miner to take it to include it in a block, its status will be “pending” and it is only here that we will be able to act on it.

If we perform the method I will explain in the next section, the original transaction, replaced or cancelled, will have the status “replaced”, once we consult it in a search engine.

Finally, two statuses. “In block” will be the status of our transaction once it has been selected by a miner and included in a block already added to the network. Here, our transaction, together with all the transactions that make up this block, are waiting for the famous confirmation that gives them the “Success” status.

Let us now learn how to act on this pending transaction.

¿Es posible cancelar o reemplazar una transacción pendiente de Ethereum?

Why cancel or replace a tx in ethereum?

The structure of a network like Ethereum, its organization and consensus, are what today allow us to cancel or replace a transaction.

Now, if you wonder why we might want to perform these actions, there are two great examples:

  • We regret it and are not interested in having it confirmed
  • It was sent by mistake

Before knowing how to cancel a transaction, one more step.

What information does a transaction contain?

The following is a list of the information contained in a transaction:

  • Recipient: The address that will receive the funds. Either an individual or a contract.
  • Signature: This is generated when, using the private key, the transaction is signed and confirmed as having been authorized by the sender.
  • Value: Amount of ETH that the sender transfers to the recipient or equivalent in another currency to be sent.
  • Data: Optional field in which arbitrary data is included.
  • Gas Limit: Maximum amount of gas units that can be consumed by the transaction
  • Gas Price: The fee the sender pays per unit of gas.
  • Nonce: A sort of counter, which lists the total number of confirmed transactions sent from the sending Ethereum address

This data, the “Nonce”, is the one we will use to cancel or replace a transaction in Ethereum.

Steps to cancel or replace a transaction in Ethereum

Once we have sent our transaction to the blockchain, and it is still pending, we will still be able to cancel or replace it. If this is what we wish to do we must follow the following simple steps:

  • Search for the “hash” or number that identifies the transaction.
  • Paste it into a search engine, such as and search for the transaction.
  • Among its data, after confirming that the status is “pending”, click on “see more”.
  • Once there, look in the “Others” row for the number of the “nonce”.
  • Go back to our wallet and in the options, usually advanced, select the manual creation of the “Nonce”.
  • We create a new transaction from our wallet, selecting a gas that exceeds the one selected in the previous one and before sending it, we modify the “Nonce” number for the one that has the transaction to be replaced.
  • We send the transaction and wait for your confirmation

Data to take into account

When creating the new transaction we will be able to perform two actions:

  • Correct the previous transaction
  • Cancel that transaction

In the first case, what we should do is to recreate the same transaction, either sending the same amount to the same address or interacting with the same contract, while correcting the erroneous parameter and selecting a higher gas, so that this transaction is prioritized for a miner. It is important to clarify, that the gas of both, will be consumed and will not be returned to us.

In the second case, when we do not want the transaction to be executed, the option usually used is to create a transaction in which we send 0 ETH to ourselves.
In this way, if this transaction has the same nonce, but more gas than the previous one, once confirmed, it will replace the unwanted transaction.

¿Es posible cancelar o reemplazar una transacción pendiente de Ethereum?

A reflection

The world behind an Ethereum transaction can be fascinating. This article is but a small sketch of what happens when sending a transaction and the options we have to actively intervene in its future.

Knowing the fundamentals and concepts behind our daily tools is not an obligation or a necessity. But it undoubtedly provides us with the necessary expertise to act with full knowledge of the facts and minimize errors.

An informed community is a community that is able to protect itself and share its knowledge with the world. There are already too many proofs that the road to adoption is built on education.

Leave a comment
Your email address will not be published. Required fields are marked *