5

I'm trying to connect to my RSK node via a websocket:

wscat -c ws://localhost:4445/websocket

However, I get this result: Error: connect ECONNREFUSED 127.0.0.1:4445.

The docs say that websocket listens to port 4445 by default.

How do I connect correctly?

Jesse Clark
  • 584
  • 2
  • 9

2 Answers2

7

Websockets are disabled by default. See RSKj configuration reference

To enable websockets on RSKj: (1) Add -Drpc.providers.web.ws.enabled=true to your java command when starting RSKj. (2) Update the configuration file. The file is named mainnet.conf for RSK Mainnet.

Your config file should look like this:

rpc {
providers : {
    web: {
        cors: "*",
        http: {
            enabled: true,
            bind_address = "0.0.0.0",
            hosts = ["localhost", "127.0.0.1"],
            port: 4444,
            }
        ws: {
            enabled: true,
            bind_address: "127.0.0.1",
            hosts = ["localhost", "127.0.0.1"],
            port: 4445,
            }
        }
    }
    ...
}

After this, restart your RSKj for the config to take effect. Now if you repeat the same command from your question:

wscat -c ws://localhost:4445/websocket

You should be able to establish a connection.

bguiz
  • 27,371
  • 47
  • 154
  • 243
serlokiyo
  • 353
  • 1
  • 9
3

You're trying to connect in a correct way.

However, make sure that you have a right to connect to this port,

For example,

rpc.providers.web.ws.bind_address=127.0.0.1

or

rpc.providers.web.ws.bind_address=0.0.0.0
  1. You have to specify that Websockets are on rpc.providers.web.ws.enabled=true
GetBlock
  • 41
  • 2