Skip to content

Invalid states should not emit events, they should revert.  #63

@3esmit

Description

@3esmit

Events are meant to be used to update the user view when relevant state changes happen.

When using events to signal errors in transaction setup, this is a waste of gas and don't give proper user feedback until the transaction is minted (of course it can be mitigated by checking before, but the checks are made more difficult with errors as events).

Examples:

https://github.com/status-im/community-dapp/blob/7836a7692981b6796fa9c9bf0ae0d5f8cce14496/packages/contracts/contracts/VotingContract.sol#L56C58-L56C58

emit NotEnoughToken(votes[i].community, votes[i].voter);

event AlreadyVoted(bytes community, address voter);

Instead, error handling should be used https://docs.soliditylang.org/en/v0.8.20/control-structures.html#error-handling-assert-require-revert-and-exceptions

When a error is thrown, the DApp can detect and handle the error, before the transaction is submitted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions