Search code examples
javascriptamazon-ec2websocketweb3jsgo-ethereum

Connect to aws ec2 node by websocket


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".


Solution

  • 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