Skip to content

watchEvent doesn't re-create filter if it was uninstalled #3948

@sidrisov

Description

@sidrisov

Check existing issues

Viem Version

2.33.2

Current Behavior

Looks like watchEvent internally validates wrong error and doesn't re-initiate the filter if it was uninstalled (latest code):

            // If a filter has been set and gets uninstalled, providers will throw an InvalidInput error.
            // Reinitialize the filter when this occurs
            if (filter && err instanceof InvalidInputRpcError)
              initialized = false
            emit.onError?.(err as Error)

I am getting InvalidRequestRpcError instead on the onError callback though:

URL: https://base-mainnet.g.alchemy.com/v2/{api_key}
Request body: {"method":"eth_getFilterChanges","params":[filter_id]}

Details: filter not found
Version: viem@2.33.2
InvalidRequestRpcError JSON is not a valid request object.

Expected Behavior

watchEvent should re-create a filter on the next poll if it was uninstalled

Steps To Reproduce

  1. start listening to watch even
  2. uninstall it
  3. keep getting error onError callback

Link to Minimal Reproducible Example

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions