Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contract.filters passing an array as OR related topic filter #437

Closed
jochenonline opened this issue Feb 26, 2019 · 6 comments
Closed

contract.filters passing an array as OR related topic filter #437

jochenonline opened this issue Feb 26, 2019 · 6 comments
Assignees
Labels
enhancement New feature or improvement.

Comments

@jochenonline
Copy link

Is it possible to pass an array of topics (a.k.a. indexed values) to contract.filters.MyEvent() like I can do it to the members of filter.topics that is passed to provider.getLogs?

@ricmoo
Copy link
Member

ricmoo commented Feb 26, 2019

That functionality isn't supported yet. It is coming though. There is a TODO in the code to add it, and it is fairly straight forward. It is just a matter of sorting and serializing nested arrays. It probably won't make it into v4, as I'm trying to finalize v5 for beta release right now. I'll add it as an enhancement for v5 though, so it should get in soon. :)

@ricmoo ricmoo self-assigned this Feb 26, 2019
@ricmoo ricmoo added enhancement New feature or improvement. next version labels Feb 26, 2019
@ricmoo
Copy link
Member

ricmoo commented May 7, 2020

This has been added to 5.0.0-beta.185 and shoaled work for both the Contract and Interface classes. :)

Thanks! :)

@ricmoo ricmoo closed this as completed May 7, 2020
@EvilJordan
Copy link

EvilJordan commented Feb 10, 2021

I always feel bad commenting on closed issues, but it's often where the question and information is most relevant.

Contract.filters.Transfer([ [ null, '0x0000000000000000000000000000000000000000' ], [ '0x0000000000000000000000000000000000000000', null ] ])

I'm trying to listen to mint and burn transfers. I can make them work individually, as one-off filters.Transfer calls, but combining in this way results in the error: invalid address (argument="address", value=[null,"0x0000000000000000000000000000000000000000"], code=INVALID_ARGUMENT, version=address/5.0.9)

As with most things in my life, I'm sure I've done something wrong, but I thought I was understanding the documentation and logic so well!

@ricmoo
Copy link
Member

ricmoo commented Feb 10, 2021

The .filters Contract method does not support OR-ed conditions, but I think the filter you are trying to create is quite different then the one that would represent. :)

That filter API you linked to is for the provider.getLogs, which is what the Contract.filters builds topic sets for. Keep in mind if you wish to use the provider.getLogs methods directly, you will need to pad the addresses to 32 bytes.

Off topic, but as a quick example of what that filter would match, if the Contract filter API supported that would be:

  • [ null ] and [ null ] (so a transfer from any to any, this is not probably what you want)
  • [ 0 ] and [ null ] (i.e. the mint, you care about this)
  • [ null ] and [ 0 ] (i.e. the burn, you care about this)
  • [0 ] and [ 0] (a mint and burn simultaneously; this prolly doesn't happen ;))

What you likely want is two separate filters:

const filterBurn = Contract.filters.Transfer(null, '0x0000000000000000000000000000000000000000');
const filterMint = Contract.filters.Transfer('0x0000000000000000000000000000000000000000', null);

The OR nature of filters gets away from you pretty quickly. It is a good idea for me to add filter address though. I will add that to my backlog for v6 which I'm tinkering with right now. :)

Does that make sense?

@EvilJordan
Copy link

This absolutely makes sense, and similar to what I tried at first, but now realize I wasn't creating multiple on() listeners, and instead overwriting the first one with the newest filter.

It's been a long week. As always, thank you for your help!

@ricmoo
Copy link
Member

ricmoo commented Feb 10, 2021

No worries. Glad to help! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement.
Projects
None yet
Development

No branches or pull requests

3 participants