- Allow to log information on the blockchain which can be access by external sources such as frontend-app, other contracts, etc.
- The smart contract need to emit the event to send to the external sources.
- It can be use for debugging, indexing or triggering external action on the contract.
contract EventsEcample {
// event is create with the parameter it req to emit with
event Transfer(address indexed from, address indexed to, uint value)
// here address of both from and to are indexed , so it would be easy to search
// the trnsaction by the address
function sendEth(address _to, uint _value) public {
// logic for send the eth to the acc
// the event is emit
// whenever the fn is called it emit the infromation to external source
emit(msg.sender, _to, _value)
}
}