JS-IPFS The dial request has no valid addresses on ipfs.swarm.connect

I am trying to connect my js-ipfs node in the browser to the kubo node running in docker. When I call await ipfs.swarm.connect(new Multiaddr(‘/ip4/127.0.0.1/tcp/4003/ws/p2p/DOCKER-KUBO-NODE-ID’));
I get the following error: Error: The dial request has no valid addresses.
Any help ?
In kubo config under swarm I appended “/ip4/127.0.0.1/tcp/4003/ws” and mapped the port in docker
I am trying to fetch a file from kubo in js-ipfs

I ran into the same problem. Turns out you can’t add localhost as a peer unless you stop IPFS from filtering out local connections (which it deems insecure).

More details are provided at How to connect from IPFS node in browser to IPFS node in terminal? · Issue #4185 · ipfs/js-ipfs · GitHub.

1 Like

As @haydenyoung mentioned, you need to explicitly allow all WebSocket connections as follows:

import { WebSockets } from '@libp2p/websockets'
import { create } from 'ipfs-core'
import { all } from '@libp2p/websockets/filters'

window.addEventListener('load', async () => {

  const ws = new WebSockets({
    //       👇 allow all WebSocket connections 
    filter: all,
  })
  const ipfs = await create({
    libp2p: {
      transports: [ws],
    },
  })
  // ---------------------------------------------  👇 note that this should be ws. wss is only supported for
  await ipfs.swarm.connect('/ip4/127.0.0.1/tcp/4003/ws/p2p/{peerId of the node running in the terminal}')
})

By default, the WebSocket transport filters out localhost WebSocket connections. This is because older versions of js-libp2p would gossip about their localhost addresses which often leads to js-ipfs attempting to connect to other peers’ localhost multi-address unsuccessfully.

You can find more context in this issue: feat: custom address filter by vasco-santos · Pull Request #116 · libp2p/js-libp2p-websockets · GitHub

1 Like