Friends, it’s time to learn blockchain technology. At the end of the bear market, watch more, do less, and learn more. After a month of spare time, I have learned the basics of solidity language. I hope to master all WEB3 related technologies before ETH reaches 10,000 US dollars. $ETH
1. What are events in the Solidity language?
External acquisition can only be used to obtain the state changes of contracts. Events are actually Ethereum's log interface. When calling a contract function, the call needs to be submitted to the Ethereum network. This process is time-consuming and usually executed asynchronously. We cannot get the result directly after submission. If we want to know the result, we can use events to receive the processing result. Events are used for external notification of contracts. Events are actually Ethereum's log interface. Logs are a special structure that can be indexed.
2. How to use solidity events?
Use the event keyword to declare an event, which is inheritable. Solidity looks like a log function in other languages.
event EventName(uint param);
Use the emit keyword to emit an event emit EventName(10)
The following figure is a practical example of the code. You can see that the log contains information about event records.
3. What is the key role of solidity events?
The main function of solidity is to monitor DAPP. The following is the pseudo code of DAPP monitoring
var ev = contractInstance.EventName();
ev.watch(function(err,result){
result.args.name;
}) ;