[Ethereum] How to reverse or cancel a transaction or recover lost ethers

transactions

Transactions (using a smart contract like a token or sending ether), by design, are immutable on the blockchain. What methods can be used to (more or less) unilaterally reverse a transaction made by myself or someone else? Situations where one might like to reverse a transaction:

  • Sent a transaction to the wrong account/wrong contract/wrong address.
  • Sent a transaction with the wrong amount of ether.
  • Buyer's remorse (e.g., transaction recipient was a scammer).
  • Recipient is not acknowledging transaction or is holding on to tokens/ether sent as part of the transaction (such as an exchange might).
  • Contract has a bug.
  • Compromised account (e.g., How to reduce the chances of your Ethereum wallet getting hacked?)
  • Transaction is "stuck" due to low gas and no longer worth performing.
  • Contract called with wrong arguments.

Best Answer

Send the inverse transaction

If there exists an inverse to the transaction (e.g. Send 3 DAO tokens from account A to account B has the inverse of sending 3 tokens from B to A), one can execute the inverse transaction. Note that a contract may implement something or an account holder may do something that is not reversible (e.g., it may burn tokens). Also note that this results in two transactions (the original plus the inverse) which both are recorded permanently in the blockchain. This also means that the transaction fees are incurred for both transactions.

Use (directly or indirectly) the private key of the recipient account

If (and only if) Ethereum is not broken, the private key of the recipient is required to send a reversing transaction from an account. TODO: please add something about sending stuff as a contract (i.e., is there a private key, even if no one knows it, associated with contracts?). In situations where you do not have the private key (such as if you send ether to an exchange and you don't receive an appropriate account balance adjustment), then you must ask the recipient to perform the reversing transaction (and hope they have the private key). If the recipient is a company, you should contact their support staff. Stack exchange members (unless they happen to work at the company in question) cannot help you.

Race to replace the transaction

If the transaction has not yet been confirmed in the blockchain and is only in the transaction pool, you can replace the transaction. This is as close as you can get to cancelling a transaction. Note that this still results in a transaction occurring (and gas being paid for).

Repost transaction

One way of replacing an unconfirmed transaction is to repost a replacement transaction with the same nonce but a higher gas price; a possible replacement transaction is to post a 0-value balance transfer with yourself as the recipient. It might be a bad idea to set a very low gas limit in case such a transaction is filtered out by a miner. This method can only be used to replace a transaction you have sent. This method works to replace any kind of transaction -- including ones for interacting with contracts such as tokens.

Create a winning fork

Since the current state of the blockchain is based on the history of the blockchain, one way of reversing a transaction is to rewrite the blockchain history starting from at least the block containing the transaction to be reversed. Forking the blockchain intentionally like this may have negative consequences for the overall Ethereum network.

51% attack (Proof-of-work)

The accepted current state of the blockchain is the longest chain. One could build a longer chain than the current chain. One way of doing this is to append blocks to the chain faster than people mining the chain containing the transaction to be reversed (the "honest" network). In order to do this (with reasonable statistical success), you need to have more hash power than the honest network. If r is the hash rate of the honest miners, your hash rate is r + x, and t is the amount of time expected for the network to have taken to make the number of confirmations on the block with the transaction to be reversed (or, as a first approximation, the amount of time since the block containing the transaction to be reversed was mined), then the expected time to reverse the transaction is rt/x, so if you have 51% of the network and you want to reverse the most recent 120 blocks with an expected block time of 30 seconds (=1 hour of mining), it would take you just over a day to reverse the transaction (49 * 1 hour / 2). Possessing (or having access to) this kind of hashing power might shake confidence in transactions on the network.

Software fork

If you can convince people securing the network (currently, this is miners) to change their mining software, you can change the rules of the network so that the transaction is reversed. Forking the network in this manner may be contentious.

Use the legal system

If you performed a transaction with someone and are unhappy with the outcome, you can try using the legal system. The legal system may compel the offending party to make good; some countries also can crack the private keys for an Ethereum account. There is nothing in Ethereum itself that allows breaking the rules of Ethereum (obviously?). The closest you can get is to make an amendment to the rules of Ethereum or a one time pardon. This is accomplished via forking (see above).

Related Topic