TypeError: peer[0].getPeerId is not a function

I’m using libp2p with orbitdb. I got a functional app at the moment and I’m testing running it on differnent nodes. Everythings seems fine until I try to “dial” in from one node to the other by calling await node.dial(remotePeerId);

This is the full log from my app and the err message:

2024-03-12 17:40:28 info: setting up winston logger
2024-03-12 17:40:29 info: starting up...
2024-03-12 17:40:29 info: ordbitdb path: /data/orbitdb/1
2024-03-12 17:40:29 info: blockstore path: /data/ipfs/1
2024-03-12 17:40:29 info: identityId: userA
2024-03-12 17:40:30 info: orbitdb address [/orbitdb/xxx]
2024-03-12 17:40:30 info: orbitdb name [xxx-IPFS-DB]
2024-03-12 17:40:30 info: libp2p peerId [12D3KooWGoTohkr7JoLztrej5yYWzeEyatgstHEnd5vaxQjsDv9x]
2024-03-12 17:40:30 info: remotePeerId [12D3KooWSRSsR4dNqLruVQjcRr2YL5dLvopZmkf1zsdL1vXkfyJL]
        const peerIdStr = peer[0].getPeerId();

*TypeError: peer[0].getPeerId is not a functi*on
    at getPeerAddress (file:///usr/src/app/node_modules/libp2p/dist/src/get-peer.js:17:35)
    at DefaultConnectionManager.openConnection (file:///usr/src/app/node_modules/libp2p/dist/src/connection-manager/index.js:299:28)
    at Libp2pNode.dial (file:///usr/src/app/node_modules/libp2p/dist/src/libp2p.js:213:50)
    at startUp (file:///usr/src/app/services/orbitdb.srv.js:115:32)
    at async file:///usr/src/app/startup/ipfs.js:4:1

Node.js v20.11.1

Hello @msalimbene ,

I think you’d probably get better help if you asked this question in the js-libp2p Technical Forum.

Cheers! :beers:

1 Like

I was able to figure this one out. I was having remotePeerId as a string, I need to convert it to “multiaddr” using the multiaddr package, so:

import { multiaddr } from 'multiaddr’;
const multiAddr = multiaddr(remoteMultiaddr);
1 Like

I’m glad you figured it out.