Skip to content

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

Description

@rin-st

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions