Establish a websocket connection with an AWS EC2 instance

After setting up a chain node on AWS EC2 instance with geth, I'm wondering if there is any additional configurations needed or which IP address should I use to connect to it? Currently, I am incorporating web3.js with the following code: new Web3.providers.WebsocketProvider('wss_address', abiOptions)

I have enabled websocket support by using --ws flag. This resulted in getting the message "WebSocket enabled url=ws://127.0.0.0.1:8546".

Answer №1

Information extracted from the Geth documentation page regarding command-line options:

--ws                                (default: false)                   ($GETH_WS)
      Activation of the WS-RPC server

--ws.addr value                     (default: "localhost")             ($GETH_WS_ADDR)
      Interface on which the WS-RPC server listens

--ws.api value                                                         ($GETH_WS_API)
      APIs offered through the WS-RPC interface

--ws.origins value                                                     ($GETH_WS_ORIGINS)
      Specific origins allowed for websocket requests

--ws.port value                     (default: 8546)                    ($GETH_WS_PORT)
      Port on which the WS-RPC server listens

--ws.rpcprefix value                                                   ($GETH_WS_RPCPREFIX)
      Prefix path for serving JSON-RPC over HTTP. Use '/' to serve on all paths.

If only using the --ws option, the default value of --ws.addr is applied and the node will only accept requests from the local machine.

You can specify the network interface that the node should listen on by providing its IP address or hostname. For example, if your server's IP is 123.123.123.123, you can use the following IP. This setup allows the node to receive WS connections specifically to this IP.

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

If you wish to listen for incoming requests from all network interfaces of the server (e.g., localhost, LAN cables, VPN tunnel, wifi, etc.), you can set the value of --ws.addr to 0.0.0.0. This configuration enables the node to accept all inbound WS connections.

geth --ws --ws.addr "0.0.0.0"

Answer №2

Executing the following 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 using this line for connection:

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

Everything is functioning correctly, gratitude for the assistance)))

P.S. In my scenario, specifying the PORT in the connection was crucial. Additionally, connecting via ws opposed to wss made the difference. Interestingly, there was no noticeable distinction when connecting via IP with or without DNS.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Searching for elements in ASP.NET with Jquery

I need help with implementing validation for textboxes and dropdown lists using jQuery in a form that contains an AJAX Toolkit's tab container. The form includes a repeater displaying search results, where users can update data. I want to prevent the ...

Create a "load additional data" button

I'm working on building my blog and I've run into a roadblock while trying to implement a load more button. Here's what I currently have: actions: { LOAD_ARTICLE_LIST: function ({ commit }) { axios.get('someurl/articles') ...

Ways to retrieve the latitude and longitude coordinates between the starting point and the destination

I need to retrieve all the latitude and longitude coordinates from Google Maps. For instance: If I input the latitudes and longitudes of a source and destination, and a path is drawn on the map like below: Now, I want to obtain all the latitude and longi ...

Utilize Express efficiently by requiring modules only once for multiple routes within the application

Here is an overview of my project directory structure: MyProject -app.js -routes -routeone -routetwo In the app.js file, I have the following setup: var express = require('express'); var app = express(); var routeone = ...

Issue: `Alert` not triggering after clicking on anchor link in AJAX response

Below is the code I am currently working with: $('.ver').click(function(e) { e.preventDefault(); var id = $(this).next().val(); $.post('cotizar_detalles.php', {'id': id}) .done(function(response) { ...

A method for setting a value from an HTML textbox to a variable and displaying it on the same page

How can I retrieve the value from a textbox and display it on the same page? The purpose behind this is that when the user enters their BTC wallet into the textbox, I want to store this value in a variable on the same page and then output the value. I at ...

The HTML button triggers a function to execute on a different webpage when clicked

I'm facing a straightforward issue that I can't seem to figure out due to my limited experience with Angular and web development. The problem revolves around two components, namely home and dashboard. In the home.component.html file, there's ...

JQuery for personalized path animations

After developing an android app that sends onTouchEvents points to a web server, I've been able to retrieve motion points JSON data using Ajax. Here is a snippet of the data: {"data":[ {"x":224.28035,"y":235.4906}, {"x":263.32916,"y":219.45718}, {"x" ...

Triggering events on click within bootstrap 3 tabs

Here is the HTML code snippet I am working with: <div id="channels"> <ul class="nav nav-tabs" id="ul-channels"> <li class="channel" data-roomid="lobby"><a class="link-channel" href="#lobby" data-toggle="tab">lobby</a ...

Searching for elements by tag name in JavaScript

Recently, I attempted to create JavaScript code that would highlight an element when a user hovers their cursor over it. My approach involves adding an event listener to every child within the first "nav" tag in the current document: let navigation = docum ...

Error: Firebase Fetch - Cross-Origin Request Blocked

Currently, I am in the process of developing an application using React + Redux, and my data is stored in a JSON database hosted on Firebase. In order to retrieve this data, I am attempting to use the fetch method with a valid URL (which has been tested an ...

I am interested in checking the dates of the current date and disabling the button if the date falls within that range

I am attempting to deactivate a button if the current date falls within a three-month period. Despite my efforts to use a combination of Php and JavaScript, I was unable to make it work. PHP Code @php($found = false) @foreach($doctors as $doctor) ...

Node.JS: Combining Multiple Files into a Single Output File

Currently, I am in the process of building a data pipeline using Node.js. While I acknowledge that there are better ways to approach this, I am determined to implement it and make improvements as I go. Here's the scenario: I have a collection of gzi ...

Is there a way to seamlessly update a field without refreshing the page or overloading the server?

I'm intrigued by the concept of updating a field dynamically without refreshing the page or overwhelming the server with queries. Stackoverflow demonstrates this feature when someone answers our question, and it instantly shows at the top of the page. ...

The useState variable is unexpectedly returning an empty array even though I have explicitly set it as an array containing objects

Hey there! I've encountered a scenario with my component where I'm utilizing the useState hook to set up the initial value of myFeeds variable to an array called feeds. I have also implemented an effect that is supposed to update myFeeds with any ...

I am experiencing an issue where the position of the value in the returned response array keeps changing after an Ajax request is made. How can

I am currently using a script that sends an array of numbers through Ajax to a web server. These numbers are then used to query a database, and the corresponding values from the table are sent back. I then display these values in respective divs within my ...

Loading asynchronous select options with a knockout observable array

I have an ajax-based asynchronous loader for select options. It accepts a remote address and returns an observable array that is correctly populated with descriptions and key values to be used in the following binding. <select data-bind="value: select ...

Disable Chrome's default click and hold/drag image behavior

Upon using Google Chrome, I have observed a functionality where one can click and hold an image, causing a semi-transparent copy of the image to attach itself to the cursor. This allows the user to drag the image to the desktop for saving purposes. I am s ...

Import JSON Data into Angular-nvD3 Chart (AngularJS)

I am seeking help to load encoded JSON Data retrieved from a database via queries into an Angular-nvD3 graph. I am unsure about the best approach to achieve this task. The encoded JSON data is fetched using API queries from a database table called PRODUCT ...

Preventing a user from inputting a value below 1 in a number input field within Vue 3

I'm working on implementing a number input field in Vue 3 that restricts the user from entering a value less than 1. Currently, I have set the minimum value to 1 to prevent using the input arrows to go below 1: <input min="1" type="n ...