Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to RSK node over websockets?

Tags:

websocket

rsk

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?

like image 283
Jesse Clark Avatar asked Feb 15 '21 13:02

Jesse Clark


1 Answers

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.

  • See RSKj node configuration for how to locate and edit the config file.
  • See RPC protocol configuration reference for a detailed explanation about the various RPC configurations available, including the ones related to websockets.

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.

like image 99
serlokiyo Avatar answered Nov 29 '22 15:11

serlokiyo