Contract Mastery: Events

Events

Events are special values that can be emitted during the execution of a program.An event type can be declared with the event keyword.

Events can only be declared within a contract body. Events cannot be declared globally or within resource or struct types.

event FooEvent(x: Int, y: Int)

Emitting events

To emit an event from a program, use the emit statement:

Events can only be emitted from the location in which they are declared.

pub contract Events {

event FooEvent(x: Int, y: Int)

fun events() {

emit FooEvent(x: 1, y: 2)

}

}

Some Core Events

Core events are events emitted directly from the FVM (Flow Virtual Machine). The events have the same name on all networks and do not follow the standard naming (they have no address).

1. Account Created - Event name: flow.AccountCreated

Event that is emitted when a new account gets created.

2. Account Key Added - Event name: flow.AccountKeyAdded

Event that is emitted when a key gets added to an account.

3. Account Key Removed - Event name: flow.AccountKeyRemoved

Event that is emitted when a key gets removed from an account .

4. Account Contract Added - Event name: flow.AccountContractAdded

Event that is emitted when a contract gets deployed to an account.

5. Account Contract Removed - Event name: flow.AccountContractRemoved

Event that is emitted when a contract gets removed from an account.