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 · 3 comments
Open
1 task done

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

rin-st opened this issue May 3, 2024 · 3 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: [email protected]
    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!

@nikitayutanov
Copy link

nikitayutanov commented May 29, 2024

Ran into the same problem, with the difference that I'm using bare watchContractEvent action (and only it, there are no another watch functions or hooks).

In my case feels like if watchContractEvent is active long enough and onError argument is provided, soon enough it'll start to return this alongside with errors specified in the original post:

    at withRetry.delay.count.count (buildRequest.ts:130:21)
    at async attemptRetry (withRetry.ts:44:22)Caused by: RpcRequestError
    at request (http.ts:131:19)
    at async withRetry.delay.count.count (buildRequest.ts:104:18)
    at async attemptRetry (withRetry.ts:44:22)

edit: related viem issue. Probably nothing to do with the libs, but rather RPC.

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

4 participants