0

I have referred, Web3 Events, but filters object is not working for me, I've got the same result for events before and after applying filter object.

Here's the code:

 instance.getPastEvents(
    "Transfer",
    {filter: {value: [117,50]}},
    { fromBlock: 0 , toBlock: "latest" },
    (errors, events) => {
         if (!errors) {
            console.log(events);
         }
     }
);

What does that filter object really means, According to documentations and references it is custom fields but it must be object parameters.

Suggestion needed to correct the filters use.

0

Filters only work if the parameter is indexed. For example, the ERC20.Tranfer event is defined as Transfer(address indexed from, address indexed to, uint tokens), so only from and to can be used in filters.

Edit: I just noticed, you're submitting the filter as a separate object. The correct format is this:

 instance.getPastEvents(
    "Transfer",
    {         
      {filter: {value: [117,50]}}, 
      fromBlock: 0 , 
      toBlock: "latest" 
    }, (errors, events) => {
         if (!errors) {
            console.log(events);
         }
     }
);
  • Yes, I am aware about it. I've also used 'to' and 'from' instead 'value', and my contract ABI also has indexed value true for 'from' and 'to'. But still I am getting entire array of an event without filters. – Rudrika Aug 31 at 5:28
  • It doesn't matter if just the ABI has them indexed, they have to be indexed at deployment time. Are you sure the parameters were marked indexed at compile time before deployment? – flygoing Aug 31 at 23:44
  • @Rudrika See my edit. I realized your issue is just around the format of parameters to getPastEvents – flygoing Sep 1 at 5:07
  • There is a change in object, for fromBlock and toBlock, But I have problem with the filter object, which is represented by an array after value. – Rudrika Sep 2 at 4:28
  • The issue isn't with the filter object, it's with where you're putting it in the parameters. It shouldn't be it's own object as the 2nd parameter to getPastEvents, it should be a property in the object that is the 2nd parameter, which always has fromBlock and toBlock. Read the edit carefully. – flygoing Sep 5 at 18:38

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.