What happens to events when you revert?

Hi there, I’m wondering if an emiited event can be reverted. Some people say an emitted event can change stage, revert can certainly revert all state changes. I am wondering why an event is also a stage change. Conceptualy, there is a subtle difference. Thanks.

1 Like

Hi @maxaero,

I suggest creating a simple example and testing it to check what happens.

Emitted Events don’t change state on chain.

You can also look at the Solidity documentation to see what you can find: https://docs.soliditylang.org/en/v0.8.3/abi-spec.html?highlight=event%20log#events

I assumed that events aren’t emitted when reverting.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract MyContract {
    event DoneStuff();
    
    function doStuff() public {
        emit DoneStuff();
        
        revert();
    }
}

You may also be interested in: Falsehoods that Ethereum programmers believe

Right, the same code gave me different results on my local computer and on Ethereum blockchains. On my computer, nothing happened, the transaction succeeded, and I got no error. Yet, on Rinkeby, the transaction got reverted and no event was emitted, hence no state change except gas fee differences: https://rinkeby.etherscan.io/address/0x02487a4ef6c05eb1b50e05a068787d1586731d48

Hoorey!

1 Like

An emitted event doesn’t change any observable state in the EVM, but it changes the state of the blockchain, because it stores a new log in every node.

1 Like