web3x icon indicating copy to clipboard operation
web3x copied to clipboard

`Legacy providers only support notification event.` when using `WebsocketProvider`

Open megaturbo opened this issue 6 years ago • 5 comments

I'm using the WebsocketProvider and I want to listen to provider events like connect, error, etc...

Right now I'm using this:

import { WebsocketProvider } from "web3x/providers";

const provider = new WebsocketProvider(ws_provider_path);
provider.on("connect", () => console.log("Provider connected."));

But I keep getting this error:

Error: Legacy providers only support notification event.

So why is the WebsocketProvider a legacy provider ? And how can I setup a non-legacy provider to listen to this kind of events ?

megaturbo avatar Aug 27 '19 13:08 megaturbo

The current websocket provider, is the legacy provider wrapped in an adapter. Unfortunately the adapter is provider agnostic so isn't setup to deal with these new events. EIP 1193 remains a moving target (12 days ago https://github.com/ethereum/EIPs/pull/2240).

Regardless, it's would be useful to have providers that meet the spec as it stands. Unfortunately I don't have time to look into this right now. Happy to look over and accept good quality PR's...

xf00f avatar Aug 27 '19 13:08 xf00f

Maybe I can help with that, I'll see what I can do when I have time.

For now, do you have any idea how to reconnect the provider after loss of connection ?

megaturbo avatar Aug 27 '19 13:08 megaturbo

It seems this may be an issue inherited from web3.js. https://github.com/ethereum/web3.js/issues/1354

Maybe the provider has been cleaned up and fixed in web3.js and can be migrated in. Right now not sure what to suggest. I maybe get a chance to look into this in next few weeks.

xf00f avatar Aug 28 '19 23:08 xf00f

any updates on this?

takahser avatar Dec 08 '19 15:12 takahser

EIP 1193 remains a moving target

@xf00f looks like EIP-1193 has been finalized: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1193.md

what's the best way to work on this?

takahser avatar Dec 27 '20 21:12 takahser