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

Filter events with multi address #3831

Closed
johnnguyen-nodejs opened this issue Feb 26, 2023 · 9 comments
Closed

Filter events with multi address #3831

johnnguyen-nodejs opened this issue Feb 26, 2023 · 9 comments
Assignees
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6

Comments

@johnnguyen-nodejs
Copy link

johnnguyen-nodejs commented Feb 26, 2023

Ethers Version

6.0.8

Search Terms

No response

Describe the Problem

i can not filter multi-address event

Code Snippet

const contract = new Contract(contractAddress, abi, provider);
const filter = contract.filters.Transfer(null, [address1, address2, ...]);
contract.on(filter, handlerEvent)

Contract ABI

No response

Errors

TypeError: unsupported addressable value

No response

Environment

No response

Environment (Other)

No response

@johnnguyen-nodejs johnnguyen-nodejs added investigate Under investigation and may be a bug. v6 Issues regarding v6 labels Feb 26, 2023
@imaksp
Copy link

imaksp commented Jun 7, 2023

Getting same error, this was new useful feature in v6 but it seems it is not working, tried with Infura provider.
@ricmoo is it ethers issue or json rpc provider service issue?

BTW I tried with provider.getLogs function.

@imaksp
Copy link

imaksp commented Jun 7, 2023

Also does it actually reduce number of Infura calls, or does it send new eth_getLogs request for each contract address?

@imaksp
Copy link

imaksp commented Jun 7, 2023

Ignore above comment I found that this could be Infura specific issue, it requires eth_getFilterLogs method for multi address support.
but with this code will be different based on provider. see if you can support it as Infura is very popular.

NOTE: it seems Infura is not spec-compliant. it should be supported as per this official specs:
https://ethereum.github.io/execution-apis/api-documentation/

@ricmoo
Copy link
Member

ricmoo commented Jun 7, 2023

Sorry. Missed this before. Looking into it now.

Does it work with other providers?

InfuraProvider should by default use a filter ID subscriber.

Can you also make sure you are on the latest version of ethers?

@ricmoo ricmoo added the on-deck This Enhancement or Bug is currently being worked on. label Jun 7, 2023
@imaksp
Copy link

imaksp commented Jun 8, 2023

Hello, sorry for the confusion error was due to potentially invalid eventFilter use like contract.filters['Approval'](null, [address1, address2], null), which may be incorrect or may not be supported yet (error comes from resolveAddress if we use filter like this).
but passing addresses array works in getLogs call. & it seems it is not supported in topicFilter.

@ricmoo
Copy link
Member

ricmoo commented Jun 8, 2023

Yes, topic filters don't support that syntax, but could have something like that added in the future (using another wrapper to indicate OR), because it would complicate refining the event. You could also use the contract to generate the filter and swap out the single address with your array and use the provider.on directly. But there isn't currently a good way to do that with the Contract API...

@imaksp
Copy link

imaksp commented Jun 8, 2023

Ok, by looking closely I found that in v5 I was using code like this to get topic filter with multiple addresses:

const eventFilter = tokenContract.filters['Approval']!(
    null,
    [address1, address2, ...],
    null
  );

& then I was passing eventFilter.topics in getLogs call.

but in v6 it gives following error:
TypeError: unsupported addressable value

Also eventFilter.topics is not available directly so need to use await eventFilter.getTopicFilter().

how can I generate similar filter in v6?

@imaksp
Copy link

imaksp commented Jun 8, 2023

For now used the following code to make it work like v5:

const erc20tInterface = new ethers.Interface(erc20Contract.abi);
const topics = erc20tInterface.encodeFilterTopics('Approval', [
  null,
  [address1, address2, address3],
  null,
]);

& I have passed these topics to provider.getLogs function.

@ricmoo
Copy link
Member

ricmoo commented Jul 25, 2023

Sorry for the delay, I better understand the problem now. This was also reported in #4259, which included a fix that help me realize the error.

This should be fixed now and released in v6.6.5.

Thanks! :)

@ricmoo ricmoo closed this as completed Jul 25, 2023
@ricmoo ricmoo removed the on-deck This Enhancement or Bug is currently being worked on. label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v6 Issues regarding v6
Projects
None yet
Development

No branches or pull requests

3 participants