【问题标题】:How to filter and access the unindexed event parameters in solidity using javascript?如何使用 javascript 在solidity 中过滤和访问未索引的事件参数?
【发布时间】:2022-08-03 16:44:22
【问题描述】:

我正在做一个项目,我有一个活动

event AddedDoctor(
        address indexed doctorAddress,
        string indexed name, 
        string indexed doctorRegistrationId,
        uint256 dateOfRegistration,
        string specialization,
        address hospitalAddress
    );

我无法访问此事件的所有参数来索引它是The Graph。我面临两个问题:

  1. string indexed name 参数已编入索引,因此event.params.name 可以访问它,但它采用Bytes 格式。在网上搜索时,我发现索引字符串或数组存储为散列而不是纯字符串。我怎么解脱。
  2. 我无法使用event.params.specializationevent.params.hospitalAddress 读取未索引的参数string specializationaddress hospitalAddress。如何访问这些未索引的参数?

    基本上我想在The Graph 中索引所有这些事件参数,以便于检索数据。我怎样才能做到这一点?

    标签: events solidity thegraph


    【解决方案1】:

    我发现The Graph 可以以字符串格式索引未索引的字符串参数,我们可以直接使用它。 indexed 字符串参数被散列到难以处理的 20 字节对象中。我找到了这个答案:

    https://ethereum.stackexchange.com/questions/6840/indexed-event-with-string-not-getting-logged

    所以,基本上我从stringarray 类型的所有参数中删除了indexed 关键字,它可以工作。

    【讨论】:

      猜你喜欢
      • 2022-08-02
      • 1970-01-01
      • 2020-07-23
      • 2022-01-15
      • 1970-01-01
      • 2020-04-23
      • 2019-07-23
      • 2022-06-17
      • 2018-02-17
      相关资源
      最近更新 更多