Search code examples
websocketsubstrate

Accessing substrate frontend running on cloud server failed


I am following this tutorial to get started with substrate https://substrate.dev/docs/en/tutorials/create-your-first-substrate-chain/.

However, since I am doing this on a cloud server, when I try to access the front end on "http://localhost:8000/substrate-front-end-template", I have to instead do "http://my-cloud-ip-address:8000/substrate-front-end-template".

This front end fails to connect with the backend with the following error:

WebSocket connection to 'ws://my-cloud-ip-address:9944/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED API-WS: disconnected from ws://my-cloud-ip-address:9944: 1006:: Abnormal Closure

Basically, the WebSocket connection is not working on my server. How do I open a WebSocket connection to the substrate node running on my server to be accessible to remote connections and not just localhost?

Note: I have disabled the firewall on my server all ports are open.


Solution

  • It is likely best not to disable the firewall, instead only open the ports you need. You likely need to set flags for your node allowing for remote access. Here is an example:

    ./target/release/node-template \
        --telemetry-url 'wss://telemetry.polkadot.io/submit/ 0' \
        --base-path /tmp/node \
        --port 30333 \
        --ws-port 9944 \
        --rpc-port 9933 \
        --rpc-cors all \
        --validator \
        --ws-external \
        --rpc-external \
        --rpc-methods=Unsafe \
        --prometheus-external \
        --name node_validator-TESTING
    

    Note that the unsafe flags should only be used for testing and you should set the ports per your needs and firewall. Telemetry is optional here too, as well as your node's name.