Use JsonRpcProvider as listener instead of WebsocketProvider #4114
-
Describe the FeatureIn ethers v5, we could listen for query events through a Json RPC, which I believe used a polling mechanism. In ethers v6, the usage of Is there a way to get the ethers v5 functionality for JSON event queries? Maybe with some kind of enum setting to decide whether to poll or filter? A few RPC providers (ie Pokt, and many public utility RPCs) don't even offer websocket RPCs, so the current functionality is a bit restrictive. For context - our purpose uses a private RPC (proxied endpoint), which doesn't quite work for websockets. While suboptimal, additional polled queries are OK. Code ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Ah! It looks like I can pass in option "polling" to ethers.js/src.ts/providers/provider-jsonrpc.ts Lines 632 to 637 in c785c1e |
Beta Was this translation helpful? Give feedback.
-
For anyone else experiencing this... try this wrapper class:
|
Beta Was this translation helpful? Give feedback.
-
Yes, it is built-into the JsonRpcApiProvider super-class for anyone to enable the feature as necessary. In v5, it never used This allows you to force polling instead of filter IDs. Also note that if it tries using a filter ID and the result is I'm going to move this to a QA discussion and mark your above solution in case anyone looks for it in the future. :) |
Beta Was this translation helpful? Give feedback.
For anyone else experiencing this... try this wrapper class: