What is idiomatic way to get peer's Multiaddr given we have its PeerId?

There exists get_authority_ids_by_peer_id which seems useful but when spinning up multiple nodes locally which connect to each other it always returns None.

Digging into it, it seems internal addr_cache (which holds PeerId -> AuthorityId -> Multiaddr mappings) is only populated when handling DhtEvent::ValueFound(...) which are not being emitted in my case.

Some background info on how I run nodes locally:

  1. spin up first node with alice account
  2. spin up 4 more nodes using also predefined accounts by setting 1. as bootnode

Looking at node logs and invoking system_peers RPC confirms nodes are connected with each other.


Seems like DhtEvent::ValueNotFound(...) events are being emitted for corresponding Kademlia get_value requests that authority-discovery worker is creating. So it's probably problem with DHT not having proper entries initially.

  • From which peer you want to get the MultiAddr? You probably want the Multiaddr of some random peer and not only from a validator?
    – bkchr
    May 23 at 16:17
  • @bkchr I want Multiaddr for any peer in the network that I'm aware of i.e. for peers that are returned in system_peers RPC
    – klbrvik
    May 23 at 16:53

1 Answer 1


Given the question in the comment, how to retrieve the addresses of all the peers the node is aware of:

  1. This is only giving you information that your node has been learned from other nodes. It doesn't mean that these are all nodes or similar.

  2. There is currently no way to access this information. You could "abuse" the the network_state function. However, as the docs already tell you, you should not use this function.

  3. I still think that you did not explained your issue well enough on what you want to achieve and thus, can not get proper help here. If I'm incorrect, you can open a pr to Substrate to give you this information in a more "stable" way, aka not using network_state.

  • Let me put it in more simpler terms hopefully explaining it better: Peers/Nodes are obviously communicating with each other therefore they know each others public ip and ports. All I'm looking to do is to get that info (ip + port in form of Multiaddr) within node. For example when spinning up node you can pass '--bootnodes' flag which is Multiaddr containing PeerId. This Multiaddr is stored somehwere - how can I retrieve it in runtime. Obviously I don't want to retrieve Multiaddrs only for bootnodes but for any node I'm connected to.
    – klbrvik
    May 25 at 8:28
  • Why do you want to have that in the runtime? What are you doing? There is no way currently to have this in the runtime.
    – bkchr
    May 26 at 9:02
  • Apologies - 'runtime' was poor term to choose. I mean in the outer node. "What are you doing?" Creating RPC which for given PeerId (or AuthorityId) will return it's Multiaddrs if node I'm invoking RPC on is connected to peer in question.
    – klbrvik
    May 26 at 9:57
  • Then you need to do what I described under point 3.
    – bkchr
    May 29 at 14:48

Your Answer

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

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