In event
is triggered, it keeps the parameters supplied in the transaction logs as an inheritable part of the contract
.
Events are member contracts that can be inherited and triggered or emitted to store transaction log arguments, which can be accessed through an address on the blockchain.
event <eventName>(parameters) ;
The following code shows the usage of the emit
to trigger a simple event
.
pragma solidity ^0.5.0;contract sample {event Save(address indexed _from, bytes32 indexed _id, uint _value);function save(bytes32 _id) public payable {emit Save(msg.sender, _id, msg.value);}}
In the provided code example, we demonstrate a simple event
(i.e., Save
).
In line 3, we instantiate a contract sample
.
In line 4, we create our event Save
.
In line 5, we create a function to trigger the event
using the emit
keyword in line 6.
The Solidity events can be visualized using the figure below.