1

I have this solidity event :

 event ValidateData(
       address professorAddr,
       address studentAddr,
       bytes32 data
    );

in Javascript I want watch the event only when the professorAddr belongs to me. so I did:

    const skillsEvent = Coursetro.ValidateData({professorAddr: "0xad170bb838d6bb3cc35bc3e278f3d44852f3470a"});
  skillsEvent.watch(function(error, result){
        if (!error)
        {
            console.log(result.args);
        } else {

            console.log(error);
        }
    });

but I receive all events even the professorAddr is different to the parameter

1

In order to receive only the event log related to professorAddr you must specify the indexed in event. Please See below:

event ValidateData(  
       address indexed professorAddr,  
       address studentAddr,  
       bytes32 data  
    );  

so adding indexed before eventType should fix it. You have to limit of maximum 3 indexed arguments per event in web3js 1.0. And also be sure that you are using web3js1.0 and above.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.