logo

Events

Smart Contract Events#

Event Option#

Events in aelf smart contracts are used to represent occurrences during execution. These events are logged in the transaction traces.

Example of an event definition:

1
message Transferred {
2
option (aelf.is_event) = true;
3
aelf.Address from = 1 [(aelf.is_indexed) = true];
4
aelf.Address to = 2 [(aelf.is_indexed) = true];
5
string symbol = 3 [(aelf.is_indexed) = true];
6
sint64 amount = 4;
7
string memo = 5;
8
}
  • option (aelf.is_event) = true; indicates that Transferred is an event.
  • To trigger this event in a contract:

    1
    Context.Fire(new Transferred()
    2
    {
    3
    From = from,
    4
    To = to,
    5
    ...
    6
    });

    External code can monitor this event after the transaction execution.

    Edited on: 15 July 2024 03:27:19 GMT+0