Getting the peer multiaddr from IPFS Swarm peers

I’m trying to decode the buffer stored in the addr key found in the output returned by the IPFS swarm peers function back to the original string. I tried to use the toString() method with all supported encodings, but the output I’m getting is not correctly decoded.

const swarm_peers = await node.swarm.peers(); 

Below is a sample output of what I’m getting���" BD�38\

How do I correctly decode the buffer?

Tried base58/64?

Will check it out tomorrow. Going to sleep :sleeping: now :slight_smile:

Hey, yeah I tried base64, it too gave incorrect output. Base58 I think isn’t supported (check this -


The buffer is based on js-multiaddr. You can see the examples in the repo to play with the buffer.

Here how you can read it:

  const peerInfos = await ipfs.swarm.peers();

Oh great, works perfectly! Thanks a lot

1 Like