solidity中的event的存储

写在前面:
本文就是简单介绍一下智能合约中event的存储数据的位置及方式(remix的展示和js代码存储的区别)。

1.测试合约代码

pragma solidity ^0.4.16;

interface interfaceContract {
    
    
    function aaa(uint num);
}

contract InterfaceImpContract is interfaceContract {
    
    
    event Receive(uint indexed num2,uint num3);
    function aaa(uint _num) public {
    
    
        uint256 num4 = _num * _num;
        Receive(num4,_num);
    }
}

备注:注意此处num2是带有indexed,但是num3没有。

2.remix界面

  • 在remix上执行aaa函数,查看返回,如下图所示
    在这里插入图片描述

3.js代码获取数据

  • 通过filters的方式不再赘述,附上链接自行享用:https://blog.csdn.net/weixin_43343144/article/details/91502148
  • 通过receipt获取数据,如下图所示
    在这里插入图片描述总结:event中添加了indexed的数据会存储在topics中以十六进制的方式存储,而没有添加indexed的数据会以十六进制的方式添加到data中存储。

猜你喜欢

转载自blog.csdn.net/qq_43234632/article/details/121465386
今日推荐