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

useWatchContractEvent doesn't work properly when using watched hooks #3883

Open
1 task done
rin-st opened this issue May 3, 2024 · 2 comments
Open
1 task done

useWatchContractEvent doesn't work properly when using watched hooks #3883

rin-st opened this issue May 3, 2024 · 2 comments

Comments

@rin-st
Copy link

rin-st commented May 3, 2024

Describe the bug

I need to listen to events using useWatchContractEvent and it's working fine. At the same time I need to watch balance of some address. I'm using technique from v1 to v2 migration guide to watch balance. But when I'm adding it useWatchContractEvent doesn't work locally (hardhat, foundry) and works from time to time on sepolia (not every event). At the same time onError of useWatchContractEvent triggers often. Example from pinned app

InvalidInputRpcError: Missing or invalid parameters.
Double check you have provided the correct parameters.

URL: https://rpc.sepolia.org
Request body: {"method":"eth_getFilterChanges","params":["0xe113405727fb7f30c30ea40767b77639"]}

Details: filter not found
Version: viem@2.9.31
    at withRetry.delay.count.count (chunk-ADKPSZLC.js?v=ae0a275b:1698:19)
    at async attemptRetry (chunk-ADKPSZLC.js?v=ae0a275b:1662:22)

Error from hardhat network:

TypeError: Cannot read properties of null (reading '0')
    at getFilterChanges (getFilterChanges.js:100:20)
    at async unwatch.emitOnBegin (watchContractEvent.js:110:32)
    at async poll (poll.js:23:13)

Link to Minimal Reproducible Example

https://stackblitz.com/edit/new-wagmi-cauhct?file=src%2FApp.tsx

Steps To Reproduce

use useWatchContractEvent and at the same time other watched value

Wagmi Version

^2.5.12 (also tried last version)

Viem Version

^2.8.16 (also tried last version)

TypeScript Version

No response

Check existing issues

Anything else?

No response

@banteg
Copy link

banteg commented May 6, 2024

filter are stateful, they don't work on public rpc providers that load balance between several nodes. i think the method needs to be updated to use eth_getLogs polling instead and maintain the filter state locally. i think there is already a fallback looking at viem documentation.

@Hotmanics
Copy link

filter are stateful, they don't work on public rpc providers that load balance between several nodes. i think the method needs to be updated to use eth_getLogs polling instead and maintain the filter state locally. i think there is already a fallback looking at viem documentation.

Could you elaborate on this?

useWatchContractEvent doesn't seem to fire when we are expecting it to.

You're saying it has something to do with the filtering?

Glad to provide dev work once we can identify the problem!

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

No branches or pull requests

3 participants