eventssoliditythegraph

How to filter and access the unindexed event parameters in solidity using javascript?


I was doing a project, and I have an event

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

I am not able to access all the parameters of this event to index it is The Graph. I am facing two issues :

  1. string indexed name parameter is indexed so it is accessible by event.params.name but it is in the Bytes format. On searching the net I found that indexed strings or arrays are stored as hashes and not plain strings. How do I get unstuck.
  2. I am not able to read unindexed parameters string specialization and address hospitalAddress using event.params.specialization and event.params.hospitalAddress. How do I access these unindexed parameters?

Basically I want to index all these event parameters in The Graph for easy retrieval of data. How can I do that?


Solution

  • I found that The Graph can index the unindexed string parameter in the string format and we can directly work with that. The indexed string parameters are hashed into into 20 bytes object which is difficult to work with. I found this answer very helpful:

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

    So, basically I removed indexed keyword from all the parameters of string or array type and it works.