Event logging
As well as storing information in state variables, you can also log information with event logging. This is useful for people who want to listen to some events. You may want to watch certain events on the blockchain, and if there is an event that you’re interested in, you may want to do something, such as giving an announcement in a social media website that the donation goal has been reached.
To understand event logging, let’s write a simple smart contract. Create a Vyper file, named EventLogging.vy
, and add the following code to it:
# @version ^0.3.0 event Donation: donatur: indexed(address) amount: uint256 @external @payable def donate(): log Donation(msg.sender, msg.value)
To log an event, you must declare an event that accepts what data you want to log. Here, you would want to log the donatur
indexed address
variable and the uint256
amount
variable. The indexed argument...