美文网首页
Solidity之Event

Solidity之Event

作者: charlieyan | 来源:发表于2018-01-24 15:45 被阅读0次

    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);
          }
      }
    

    相关文章

      网友评论

          本文标题:Solidity之Event

          本文链接:https://www.haomeiwen.com/subject/lryuaxtx.html