I am currently learning core-development in go-ethereum. I am a little weak with networking, RPC and connections.

I am trying to write a function in my own consensus mechanism that gathers all currently connected node addresses into a struct and then uses it to display them. it currently has a structure like this.

type NodeAddresses struct {
    connectedNode []ConnectedNode

type ConnectedNode struct {
    address common.Address

func GatherNodeAddresses() {
    nodes := &NodeAddresses{


What I'm having trouble with is how to populate the struct of NodeAddresses with connecting nodes in a private network. Each node has their own personal account set up with an address. Could someone give me an insight of how to move forward from here? Cheers!

  • Are all these nodes connected as peers ? Commented Dec 6, 2018 at 10:56
  • Yep, all nodes are connected as peers using admin.addPeer("enode...") etc
    – Yanzal
    Commented Dec 6, 2018 at 20:10

1 Answer 1


You can use an approach similar to graph traversal https://en.wikipedia.org/wiki/Graph_traversal

  1. Connect to a node, add it to "knownNodes" map
  2. Find peers for this node Get a peer list for my geth node
  3. For each peer, if peer does not already exist in "knownNodes", perform steps #1 and #2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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