Can't subscribe to infura mainnet using websockets. Ropsten works fine

I have a dapp with a node js server that uses websockets to connect to infura. I have the following line:

web3 = new Web3(new Web3.providers.WebsocketProvider('wss://'))

and it works great. This line however does not:

web3 = new Web3(new Web3.providers.WebsocketProvider('wss://'))

And neither of the following mainnet lines work:

web3 = new Web3(new Web3.providers.WebsocketProvider('wss://'))
web3 = new Web3(new Web3.providers.WebsocketProvider('wss://'))

The error I get is simply “connection not open on send()”.

I know that my infura is set up properly because I am able to successfully migrate my project using truffle using the “” endpoint (didn’t try mainnet yet as I don’t want to if I can’t get my node server working).

1 Like

Update: turns out its mainnet not main. When I change the above to mainnet it works, but only for the non authenticated version. How do I get it to work with the authentication version?

Hi @mcplums this appears to be unusual, to confirm, it is definitely mainnet and not main, can you confirm that you are using a Project ID generated from our current Infura dashboard as MYID in your example? If so, can you provide the email associated with the account so I can diagnose further.

I confirm that I am using mainnet not main and that I am using a project ID generated from the current dashboard. My email address is andrew at stanger dot co dot uk. Thanks in advance buddy

Looks like your URL is incorrect actually, try wss://

That was the problem!! Thanks :slight_smile:

However I got the url I used from my project page- under keys, for endpoint mainnet, it gives the url without the /ws/ . So this is likely giving the url for http not websockets? I think this could be clearer on the project page.

Very much agree, we are tracking an issue to improve the URL generator.