如何使用javascript过滤和访问solidity中的未索引事件参数



我正在做一个项目,我有一个事件

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中对所有这些事件参数进行索引,以便于检索数据。我该怎么做?

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

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

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

最新更新