Reading assignment - Solidity Events

    1.How are events declared?

Events are declares by using the keyword event;
Events are defined within the contracts as global and called within its functions.
followed by an identifier and the parameter list.
The parameter values are used to log the info and are saved as part of the transactions inside the block.

2.How can we emit events?

We use emit keyword, followed by the name of the event and the arguments in paranthesis.
emit EventName(); to call events explicitly.

3.How and where do we listen for events?

three parameters with the indexed attribute make a structure known as ā€˜topics’. These topics allow you
to search for events by the address of the contract that emitted the event.
A place we can listen for events is when filtering a sequence of blocks for certain events. Filter by
address of the contract that emitted the event.
*Listening for events have to be implemented on a service outside of the blockchain which forwards events to the contract. =====>>> like through a front-end app/
BUT a contract cannot listen to events.

#1…correct;
#2 elaborate more, like how do we write it in the function?
#3. correct, also through a front-end app/functionality.

  1. Events are declared using the event keyword followed by the name of the event and its parameters in parentheses

  2. To emit an event from within a Solidity contract, we can call the given event function.

  3. In the frontend application, we can use the web3.js subscribe(ā€œlogsā€) method to filter logs that match certain criteria and then use the watch method to listen for changes to the event

1 Like