0

I want to be able to connect to any available node on my private Ethereum network.

I think the requirement is similar to the service offered by Infura. I want to be able to replicate similar behavior on a private, locally hosted Ethereum network.

I currently use the following code to connect to a node on my Ethereum network:

client, err := ethclient.Dial("http://localhost:8545")
// do stuff

The end result expected is to basically improve the availability of the network. So, for arguments sake, if the node at 8545 isn't available, it will use the node at 8546 and so on...

I hope the question is clear enough. Thanks!

Volker
  • 40,468
  • 7
  • 81
  • 87
user538578964
  • 723
  • 9
  • 25
  • By some sort of list of endpoints to try and some sort of retry mechanism. What have you tried? What specifically is your question? – Adrian Mar 27 '19 at 16:12
  • @Adrian nothing yet. I was trying to find out how Infura works and replicate that behavior but so far no luck. By list of endpoints do you mean to have all the available nodes and try each one by one? – user538578964 Mar 27 '19 at 16:13
  • 1
    A simple solution is to have a list of your nodes and try them one by one until the Dial() call succeeds. A more scalable solution is to implement some way of fetching a list of nodes and use that. Possibly implement a periodic heartbeat to find unavailable nodes before you need to connect. – Mad Wombat Mar 27 '19 at 16:20
  • @MadWombat I understood your first suggestion. If I were to implement the latter one, wouldn't you need the periodic heartbeat to find the available nodes? Thanks for your answer – user538578964 Mar 27 '19 at 16:45
  • 1
    No. You do not strictly need heartbeat to maintain a dynamic list of nodes. Depending on your specific architecture, you could just have a node register with a discovery service like consul or add itself to the list in some other way and then you would have a list of nodes. You could drop nodes off the list if they don't respond or you could always keep everything or do any other logic. Heartbeat would help you connect faster by detecting unavailable nodes before the connection attempt is made. – Mad Wombat Mar 27 '19 at 17:16
  • @MadWombat Alright I gotcha. I gotta read up on the discovery service you mentioned but I'll try to see if I can do it on my own from here. Thank you very much for your answer. – user538578964 Mar 27 '19 at 19:01
  • Depending on how many nodes you are talking about you might not need a special service. You could just have nodes write a key into a redis cache or whatever else you want to use. Or if your nodes are all running on localhost you could just write a file somewhere. – Mad Wombat Mar 27 '19 at 20:12

0 Answers0