CONNECTION ERROR: Couldn't connect to node on WS with "wss://mainnet.infura.io/ws/v3/key"

it working when run rinkeby or ropsten but error "Couldn’t connect to node on WS " with mainnet. Someone can help me. Thanks

Can you provide your code generating the WS connection and the full error response?


This is picture error when connect to websocket mainnet. While I connect to testnet still working.

When trying to onEvent from contract, it gets ‘end connect socket’.
Before that, it still works normally.

I use web3@1.0.0-beta.33

This is code

var Web3 = require(‘web3’);
var provider = new Web3.providers.WebsocketProvider(“wss://mainnet.infura.io/ws/v3/b3bb2420beaf42ba92bfd850ba3f1905”, 30000)
var websocket = new Web3(provider)

var ABI = […];
var address = ‘…’;

provider.on(“connect”, ()=>{
let socket_contract = new websocket.eth.Contract(ABI, address);
socket_contract.events.allEvents({fromBlock:7922783,toBlock:‘latest’},async function (error,events) {
if(error){
console.log('Error Main Core: ',error);
}else {
console.log(‘Event…’);
}
});
})

provider.on(“end”, ()=>{
console.log(“provider end”)
})

Hope you can help me.

Couple things to try,

  • Update to the latest version of web3.js
  • web3,js is using a filter not a subscription, it is possible this is causing the timeout, how much time passes before you receive this error?

Hello.

I’ve confirmed that I could connect to mainnet using your v3 key (wss://mainnet.infura.io/ws/v3/b3bb2420beaf42ba92bfd850ba3f1905).

Jee$ wscat -c wss://mainnet.infura.io/ws/v3/b3bb2420beaf42ba92bfd850ba3f1905
connected (press CTRL+C to quit)
> 

I also tried using web3@1.0.0-beta33 and tried getting allEvents from another contract I have access to. ( I couldn’t use your ABI or address since it’s not part of your code snippet) I used your exact same code but with just another abi and address and I’m currently getting events.

Let me know if there’s something else we could try to help you debug this.