1

So I have a dapp that includes a node server, which I have got to work successfully using ganache, using this line:

web3 = new Web3(new Web3.providers.WebsocketProvider('http://127.0.0.1:8545'))

I have deployed my project to ropsten and would like to use infura for that, so I changed the code to:

web3 = new Web3(new Web3.providers.WebsocketProvider('wss://ropsten.infura.io/v3/PROJECTID'))

Obviously I did use my actual projectID. But I get this error: " UnhandledPromiseRejectionWarning: Error: connection not open". This is the same error I get when I use my localhost URL but forget to start ganache.

I know that my infura is set up properly because I am able to successfully migrate my project using truffle using the "https://ropsten.infura.io/v3/PROJECTID" endpoint.

As a test I tried to connect via http instead of wss, ie using this line:

web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/v3/PROJECTID'))

and this gives me a DIFFERENT error: "UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'returnValues' of null"

Wat do? I'm using my node server to listen for events, so I'm not sure if I can use http even if it did work- I believe that I need to use websockets for events.

2
  • Are you behind proxy?
    – Sanjay S B
    Commented Sep 16, 2019 at 11:26
  • Nope not using a proxy. Commented Sep 16, 2019 at 11:31

1 Answer 1

1

I fixed this, the URL was wrong instead of

web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/v3/PROJECTID'))

it should be

web3 = new Web3(new Web3.providers.HttpProvider('https://ropsten.infura.io/ws/v3/PROJECTID'))

The mistake was on infura's website, I have informed them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.