2

I have an event with two indexed arguments orderId and status. Filtering works fine when I filter the event on orderId which is uint.

I am not able to filter the events on the second argument (status) which is bytes32

event StatusChange( uint indexed orderId ,bytes32 indexed status );

I try to filter the StatusChange event

On executing the below code I get all the StatusChange events . I want to get only those events where the status is "New"

myContractInstance.StatusChange({status:"New"}, { fromBlock: 0, toBlock: 'latest' }).get( function (error, log) {
    if (error)
        console.log('Error in myEvent event handler: ' + error);
    else
        console.log('myEvent: ' + log);
});

Please help me know what am I doing wrong here.

  • It's rather odd to get all the events. I would expect you to get zero events if there was a problem with filtering... Also note that with some implementations (testrpc, ethereumjs) fromBlock needs to be 1, not zero, because of a bug. Again, that would leave you with LESS events, not all of them... – Paul S Oct 16 '17 at 16:27
0

Yes, you can filter for a bytes32 parameter.

However, "New" is a string not a bytes32. The easiest way to proceed would be to take off the filter and capture all the logs so you can see what the actual value looks like in the logs, then make sure you're filtering for that. You may need a conversion step when you do the filter, or you may need to convert the data when you create it, depending how you're currently doing that.

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.