WS connection error

Hi. The project worked for more than a year, but now it has crashed and does not start.

I receive that error:

WS connection error _Event {
  type: 'error',
  isTrusted: false,
  _yaeti: true,
  target: 
   W3CWebSocket {
     _listeners: {},
     addEventListener: [Function: _addEventListener],
     removeEventListener: [Function: _removeEventListener],
     dispatchEvent: [Function: _dispatchEvent],
     _url: 'wss://mainnet.infura.io/ws',
     _readyState: 3,
     _protocol: undefined,
     _extensions: '',
     _bufferedAmount: 0,
     _binaryType: 'arraybuffer',
     _connection: undefined,
     _client: 
      WebSocketClient {
        domain: null,
        _events: {},
        _eventsCount: 0,
        _maxListeners: undefined,
        config: [Object],
        _req: null,
        protocols: [],
        origin: undefined,
        url: [Object],
        secure: true,
        base64nonce: 'Q+yRwcfNXmQpK0NzlpTrxg==' },
     onerror: [Function],
     onclose: [Function],
     onmessage: [Function],
     onopen: [Function] },
  cancelable: true,
  stopImmediatePropagation: [Function] }

I made simple example with error:

{
  "name": "test.org",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "dependencies": {
    
    "web3": "^1.2.6"
  }
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
}


const Web3 = require('web3');

let provider = new Web3.providers.WebsocketProvider("wss://mainnet.infura.io/ws");
let web3 = new Web3(provider);

provider.on('error', e => {
    console.error('WS connection error', e);
    console.log('Manual process exit');
    process.exit(1);

});

provider.on('close', e => {
    console.error('WS connection close', e);
    console.log('Manual process exit');
    process.exit(1);

});

provider.on('end', e => {
    console.log('WS connection end', e);
    console.log('Manual process exit');
    process.exit(1);
});

provider.on('connect', () => {
    setInterval(async() => {
        console.log(await web3.eth.getBlockNumber());
		
    }, 10000);
});

What’s wrong?

Hi @Steelclad and welcome to our community site.

For your project, we now enforce the use of a valid Project ID when connecting. The endpoint will look like this: wss://mainnet.infura.io/ws/v3/YOUR-PROJECT-ID

To create a Project ID, you can login to the Dashboard and generate a new project, once you’ve done that your Project ID can be used in that URL and you should be all set.

Hope this helps!

Nice! It works. Thanks