事件将日志写入区块链,应用程序通常使用区块链来监控区块链状态,并将其作为在不使用状态变量的情况下在区块链上存储数据的更便宜的替代方案。 通过对事件的参数编制索引,可以高效地搜索事件。 最多可以索引3个参数。
# @version ^0.3.7
# up to 3 index
event Transfer:
# enables quick search of all Transfer events where sender is a certain address
sender: indexed(address)
# enables quick search of all Transfer events where receiver is a certain address
receiver: indexed(address)
amount: uint256
@external
def transfer(receiver: address, amount: uint256):
# some code ...
log Transfer(msg.sender, receiver, amount)
@external
def mint(amount: uint256):
# some code ...
log Transfer(ZERO_ADDRESS, msg.sender, amount)
@external
def burn(amount: uint256):
# some code ...
log Transfer(msg.sender, ZERO_ADDRESS, amount)
Yanbo的Twitter|Web3Club的Twitter
加入Web3Club 官方讨论群:YanboTravelAllWorld(微信号)