I put an emit Event(uint256 value) inside a function with view. But I got the below compile error by using npx hardhat compile:

TypeError: Function declared as view, but this expression (potentially) modifies the state and thus requires non-payable (the default) or payable.

I wonder why emitting an event is considered as a state change as it's not really touching the internal state of the contract?

1 Answer 1


Events don't change the state of the contract where they are emitted but they change the state of the whole blockchain.

In simple terms, a log (emitting an event) will make a change in the Transaction Receipts Root that is recorded in the header of a block and a adding new block is considered a change in the state of the blockchain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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