Closed facelinker closed 4 years ago
In 1.0 you use web3.eth.subscribe. But this will only work on websocket. And IPC connections.
If there is a case for we adding the old filter, we can discuss it here
Docs don't mention subscribe
here: https://github.com/ethereum/wiki/wiki/JavaScript-API
Is it still safe to use filter on an older version of web3.js? What's the reason it's being deprecated?
web3 version 0.20 is web3.eth.filter
, version 1.0 (in beta) is web3.eth.subscribe
. You'll want to check your web3 version.
As @frozeman said, subscribe
will not work with an HTTP Provider, only websocket and IPC. Web3 1.0 uses pub/sub listening for logs/events, while web3 0.20 used polling.
Correct docs link here
So what is our option with web3@1.0 when we want to listen to events using http provider?
@szerintedmi @frozeman Might be we need to implement HTTP/2. It will be awesome to use subscribe
with HTTP provider.
any solution would be great. Our workaround is ethers.js just for subscribe and getLogs which works like a charm. But not really happy pulling in a whole, overlapping functionality lib just for that.
Does the subscription function support start and end block like the filter method?
@jamesmorgan Yes, it does. Hopefully, we can soon implement the Http 2.0 subscriptions.
I would like to share my experience working with the new subscribe feature. We have 4 different microservices, which use web3.eth.subscribe method and major problem is that after a day or few, a subscription is dropped (it seems it is Geth's fault), but we don't get any errors or anything. It just stops listening for new contract events. The temporary solution we found is to restart our applications regularly (once a day), but sometimes it doesn't help because subscription can be lost only after a few hours.
So to sum, it would be really nice to implement pulling algorithm using HTTP interface in web3 v1. Also, JSON-RPC2.0 Geth feature was marked as experimental not so long ago. For short-lived subscriptions, we haven't yet encountered any problems
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions
When i call web3.eth.filter() compiler throw error "TypeError: web3.eth.filter is not a function".