Module Event

Module events are global event streams identified by a struct type. To define an event struct, add the attribute #[event] to a normal Move struct that has drop and store abilities.

Because events are ephemeral on chain, but they will be indexed and stored off-chain, so the event struct must have drop and store abilities. For example,

// 0xcafe::my_module_name
// An example module event struct denotes a coin transfer.
struct TransferEvent has drop, store {
sender: address,
receiver: address,
amount: u64

And then create and emit the event:

// Define an event.
let event = TransferEvent {
sender: 0xcafe,
receiver: 0xface,
amount: 100
// Emit the event just defined.