What are Events in Solidity?
Solidity Events are the same as events in any other programming language. An event is an inheritable member of the contract, which stores the arguments passed in the transaction logs when emitted. Generally, events are used to inform the calling application about the current state of the contract, with the help of the logging facility of EVM. Events notify the applications about the change made to the contracts and applications which can be used to execute the dependent logic.
Creating an event
Events are defined within the contracts as global and called within their functions. Events are declared by using the event keyword, followed by an identifier and the parameter list, and ends with a semicolon. The parameter values are used to log the information or for executing the conditional logic. Its information and values are saved as part of the transactions inside the block. There is no need of providing variables, only datatypes are sufficient. An event can be called from any method by using its name and passing the required parameters.
event <eventName>(parameters) ;
Result in the console:
Index in events: We can also add an index to our event. On adding the different fields to our event, we can add an index to them it helps to access them later but of course, it’s going to cost some more gas!
IMP: We can add atmost 3 indexes in one event.
Output in the console: adding the output in the console