What does it mean to revert a transaction?
Let's first talk about what it means to revert a transaction. When you revert a transaction, you essentially make it like the transaction never happened. You halt the execution of the transaction and you remove all state changes. The transaction can still be included in a block, and when it is, the transaction sender will still have to pay for the gas used.
Technically, message calls can be reverted and caught in the contract making the message call (the
msg.sender). You won't see this used too often, but this is what
catchis for in Solidity (see the docs here).
Let's take a look at a recently reverted transaction here.
If you look at the error message, it is an error that is coming from Uniswap saying
UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT'. Oftentimes, when interacting with a decentralized exchange like Uniswap, the conditions will change between when the EOA signs the transaction and when the transaction is included in the block. It's perfectly possible that when the EOA signed this transaction, the conditions of the market would have allowed for this transaction to happen, however, at the time when it was included in the block it failed one of Uniswap's checks.
You'll notice that there still was an associated gas fee since this transaction did run in an Ethereum block up until that point of the revert. Since this transaction reverted, the state changes did not go through and no token balances were updated for the user.
Alchemy University offers free web3 development bootcamps that explain more about reverting Ethereum transactions and help developers master the fundamentals of web3 technology. Sign up for free, and start building today!
Updated 9 months ago