Solidity之Event

Event是以太坊只能合约里面的一个成员就像下图里一样:


image.png

那么Event到底是什么呢?是用来干什么的呢?下面是官网上给出的介绍:

Events are convenience interfaces with the EVM logging facilities

Event可以方便地使用EVM日志记录工具,而这些工具又可以在一个Dapp的用户界面中“调用”JavaScript callbacks,这些JavaScript callbacks是用来listen for these events的。

Events are inheritable members of contracts. When they are called, they cause the arguments to be stored in the transaction’s log - a special data structure in the blockchain. These logs are associated with the address of the contract and will be incorporated into the blockchain and stay there as long as a block is accessible

Event是可继承的合同成员。当它们被调用时,它们使得参数被存储在 交易的日志 中 - 区块链中的一块特殊数据结构。这些日志与合同所属的地址相关联,将被并入区块链中并保存在上面,和所属的该区块共存不离不弃。日志和事件数据不能从合同内访问(连从创建它们的合同内都不行)。

  pragma solidity ^0.4.0;
  
  contract ClientReceipt {
      event Deposit(
          address indexed _from,
          bytes32 indexed _id,
          uint _value
      );
  
      function deposit(bytes32 _id) public payable {
          // Any call to this function (even deeply nested) can
          // be detected from the JavaScript API by filtering
          // for `Deposit` to be called.
          Deposit(msg.sender, _id, msg.value);
      }
  }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容