0

I have a blockchain deployed in a cluster. I have a geth instance running in a cluster-node and another one in another cluster-node, making a blockchain. I want to run an script which needs to access to the providers in both cluster-nodes. For example:

node1 - ws:127.0.0.1:3001
node2 - ws:127.0.0.2:3002

In the script I add the providers as:

var web3Provider_1 = new Web3(new Web3.providers.WebsocketProvider('ws://127.0.0.1:3001'));
var web3Provider_2 = new Web3(new Web3.providers.WebsocketProvider('ws://127.0.0.2:3002'));

Locally it works, but in the cluster the script cannot find the providers:

Error: Please provide an valid Web3 provider

What is the way to access to the providers to the different nodes in the blockchain from an script running in cluster-node?

0

This sounds like general network topology, no?

You have this:

var web3Provider_1 = new Web3(new Web3.providers.WebsocketProvider('ws://127.0.0.1:3001'));
var web3Provider_2 = new Web3(new Web3.providers.WebsocketProvider('ws://127.0.0.1:3002'));

And that will probably connect to the local one, but the other one wouldn't be on localhost a.k.a 127.0.0.1 - it would be wherever it is. So ...

var web3Provider_1 = new Web3(new Web3.providers.WebsocketProvider('ws://127.0.0.1:3001'));
var web3Provider_2 = new Web3(new Web3.providers.WebsocketProvider('ws://<OTHER_HOST_IP_ADDRESS>:3002'));

It might be more manageable to run the same script everywhere, so after ensuring the right ports are open:

var web3Provider_1 = new Web3(new Web3.providers.WebsocketProvider('ws://<NODE_A_IP>:3001'));
var web3Provider_2 = new Web3(new Web3.providers.WebsocketProvider('ws://<NODE_B_IP>:3002'));

I can't think of a reason to jump around hosts like this, but I think that would be the general idea.

Hope it helps.

  • I was doing that and I get the same error.. It also happens with the address of the same node that the script is running. But there is no problem with these addresses connecting peers between nodes. – sapiensapiens Feb 5 at 7:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.