skip to Main Content

I have created a chain node on aws ec2 instance using geth.
Do I need to enable something or what ip should I use to connect to it?
I am using web3.js using new Web3.providers.WebsocketProvider(‘wss_address’, abiOptions)

I enabled ws for it using –ws. Where I got "WebSocket enabled url=ws://127.0.0.0.1:8546".

2

Answers


  1. Chosen as BEST ANSWER

    With this command:

    nohup ./geth --config ./config.toml --datadir ./node  --cache 8500 --rpc.allow-unprotected-txs --txlookuplimit 0  --ws --ws.addr "0.0.0.0" --ws.origins "*" --ws.api "web3, eth" &
    

    And this line to connect:

    new Web3.providers.WebsocketProvider('ws://yourPublicIpAddress:8546', abiOptions)
    

    All working, thanks for support)))

    P.S. In my case, it was the connection with PORT specification that worked. And only through ws, not wss. And I didn't notice any difference when connecting via IP with or without DNS


  2. From the Geth docs page on command-line options:

    --ws                                (default: false)                   ($GETH_WS)
          Enable the WS-RPC server
    
    --ws.addr value                     (default: "localhost")             ($GETH_WS_ADDR)
          WS-RPC server listening interface
    
    --ws.api value                                                         ($GETH_WS_API)
          API's offered over the WS-RPC interface
    
    --ws.origins value                                                     ($GETH_WS_ORIGINS)
          Origins from which to accept websockets requests
    
    --ws.port value                     (default: 8546)                    ($GETH_WS_PORT)
          WS-RPC server listening port
    
    --ws.rpcprefix value                                                   ($GETH_WS_RPCPREFIX)
          HTTP path prefix on which JSON-RPC is served. Use '/' to serve on all paths.
    

    If you only specify the --ws option, the default value of --ws.addr is used and the node listens for incoming requests only from the local machine.

    You can specify the network interface, which the node listens on, by its IP address or hostname. For example if your server’s IP is 123.123.123.123, you can specify the following IP. This enables the node to accept WS connections to this IP.

    geth --ws --ws.addr "123.123.123.123"
    

    Or you want to listen to incoming requests from all network interfaces of the server (e.g. localhost, all LAN cables, VPN tunnel, wifi, …), you can specify the value of --ws.addr as 0.0.0.0. This enables the node to accept all incoming WS connections.

    geth --ws --ws.addr "0.0.0.0"
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search