Skip to content

2.10. Events#

Syntax#


EventDefinition = (* event_keyword: *) EVENT_KEYWORD
(* name: *) IDENTIFIER
(* parameters: *) EventParametersDeclaration
(* anonymous_keyword: *) ANONYMOUS_KEYWORD?
(* semicolon: *) SEMICOLON;

EventParametersDeclaration = (* open_paren: *) OPEN_PAREN
(* parameters: *) EventParameters
(* close_paren: *) CLOSE_PAREN;

EventParameters = ((* item: *) EventParameter ((* separator: *) COMMA (* item: *) EventParameter)*)?;

EventParameter = (* type_name: *) TypeName
(* indexed_keyword: *) INDEXED_KEYWORD?
(* name: *) IDENTIFIER?;

Event Definitions#

Events are convenient interfaces with the EVM logging facilities. They have to be defined inside a contract:

contract MyContract {
    // Defining an event
    event BidPlacedEvent(address bidder, uint amount);

    function bid() public payable {
        // Triggering an event
        emit BidPlacedEvent(msg.sender, msg.value);
    }
}

Note

This section is under construction. You are more than welcome to contribute suggestions to our GitHub repository.