We present the new instruction
emit to emit an event, in a similar an event is emitted in languages like solidity.
This feature was suggested by Nomadic Labs.
An event is declared with the
event keyword, similarly to a record:
emit instruction is then used in an entrypoint as illustrated below:
Event sink deprecated
The emition of an event generates a call to a contract called event sink. This contract provides a single entrypoint named event which takes an argument typed
The code of the event sink contract is then:
emit instruction builds the event argument as a triplet of:
- the event name
- the event annotated Michelson type
- packed value of the event data
In the example of the HighestBidIncreased presented above, the following
is equivalent to:
A Typescript library, called the crank, is available to retrieve event data from a DApp.
The crank receives events from contracts and executes event handler functions.
For example, the
handleHBI function below is executed when a
HighestBidIncreased event is emitted by the contract:
The HighestBidIncreased type and register_HighestBidIncreased function are bindings code generated by completium CLI:
The Bulb DApp example is available here.
The bulb is switched on/off by receiving events from the bulb contract. The contract is designed as a simplistic state machine with On and Off states. Two events
SwitchedOff are defined and emitted respectively by
A live bulb demo is available here.