Closed matisalimbene closed 5 months ago
Is remotePeerId
a string? If so you need to convert it to a PeerId
first see the types of the peer
arg in the API docs: https://libp2p.github.io/js-libp2p/interfaces/libp2p.index.Libp2p.html#dial
import { peerIdFromString } from '@libp2p/peer-id'
const peer = peerIdFromString('12D3KooWSR...')
If it's already a PeerId
, could you share a bit more of your code or a link to a repo please?
@achingbrain Thanks, that was it. It was a string. Now I’m getting the error ('The dial request has no valid addresses', codes.ERR_NO_VALID_ADDRESSES)
but I understand that I need to provide a multiaddrs for the PeerID, correct?
If I get the data for my local peer, I see that it has no addresses:
{
addresses: [],
protocols: [
'/floodsub/1.0.0',
'/ipfs/bitswap/1.0.0',
'/ipfs/bitswap/1.1.0',
'/ipfs/bitswap/1.2.0',
'/ipfs/id/1.0.0',
'/ipfs/id/push/1.0.0',
'/libp2p/circuit/relay/0.2.0/stop',
'/meshsub/1.0.0',
'/meshsub/1.1.0',
'/orbitdb/heads/orbitdb/zdpuAwaoeS9hQ28vKwbAJFnJKMduyRnHrbugSFk4Ffuqkj77p',
'/webrtc-signaling/0.0.1'
],
metadata: Map(2) {
'AgentVersion' => Uint8Array(31) [
108, 105, 98, 112, 50, 112, 47, 49,
46, 50, 46, 52, 32, 85, 115, 101,
114, 65, 103, 101, 110, 116, 61, 118,
50, 48, 46, 49, 49, 46, 48
],
'ProtocolVersion' => Uint8Array(10) [
105, 112, 102, 115, 47,
48, 46, 49, 46, 48
]
},
tags: Map(0) {},
id: PeerId(12D3KooWEyLcVkAsajY4NAXc2DYy5vM4ZPWpBB283DNjX44emrZc),
peerRecordEnvelope: undefined
}
Does this mean that I need to create/configure my local peer manually instead of relying on libp2p? Thanks for your help.
If you are trying to dial a remote peer by it's peer id, it has to be discoverable by some means in order for your node to get the multiaddr to dial.
There are several peer discovery modules, such as @libp2p/mdns
for local networks, @libp2p/bootstrap
for connecting to nodes on startup, etc, or the peer should be resolvable via the peer routing - this means it's functioning as a DHT server (va @libp2p/kad-dht
) or it's known to a delegated router or something else depending on your configuration.
If your peer is not discoverable then you'll need to know an explicit multiaddr to dial, and that multiaddr must use transports that the dialing node is configured with.
Perfect. Thanks @achingbrain! Should I close this issue? It’s done for my part.
when calling
await node.dial(remotePeerId);
I get