Consider the following contrived contract function:

function submitOffer(uint256 foo) public payable {
    emit MyEvent(foo);
    // then later...
    require(foo > 10, "Foo must be greater than 10");

This function emits an event on the first line, then later checks some require condition. If the condition fails, any state changes are reverted. Will this cause the event to be "reverted" (or never actually emitted) as well? I assume the answer is yes because the transaction will never actually get included in a block, but is there something I'm not considering?


Well, yes.

If a transaction reverts, from the blockchain's state of view, it's like it never happened. No changes are stored. But the transaction is still visible off-chain, as a reverted transaction - but still no changes are stored, and this includes also event emittance.

A reverted transaction is included in a block, so in that sense it's a regular transaction. So it does leave a permanent trace.

  • So the record of the failed transaction will exist on the blockchain, but the event will not appear in the logs for the contract, and anyone observing the event with web3 will not be notified that the event has fired, correct? – daltonclaybrook Apr 4 at 19:52
  • 2
    correct. The transaction is processed as "all or nothing". If it reverts, everything reverts. – Lauri Peltonen Apr 4 at 21:06
  • @LauriPeltonen What is the purpose of the record remaining on the blockchain if the transaction is "atomic"? Who is it for? – YulePale May 27 at 14:59
  • Well, a reverted transaction is also a valid transaction. It just has a (probably) undesired result. Furthermore, blockchains are immutable – Lauri Peltonen May 27 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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