Search code examples
javascriptbrowseripfsdhtjs-ipfs

IPNS name published in browser with js-ipfs won't resolve on gateway or local node


I am working on a browser application which uses js-ipfs. After I publish an ipfs address (e.g. /ipfs/Qm...), I successfully get the returned name (i.e. /ipns/Qm..). But the problem is that I can't resolve it anywhere else (local node's gateway, public gateway etc.), but within the same browser application, which is very problematic...

How can this be solved? I believe it has something to do with DHT not being supported within browser, but have no idea how to solve it whatsoever...


Solution

  • Your node needs to be dialable by other nodes for them to be able to resolve content or IPNS names, etc from you. For the browser this means using a WebRTC transport and connecting to a WebRTC signalling server. Other nodes connected to the same signalling server will be able to dial your node.

    See the browser-exchange-files example for how two browser nodes can discover each other via a WebRTC signalling server.

    The public gateways run go-IPFS which doesn't have a WebRTC transport yet so they can't dial your node to resolve the name.

    If you want your IPNS name to be resolvable after the user closes their browser you'll need to ensure it's being propagated on the network somewhere, either by standing up a long-lived go-IPFS node yourself which you control via it's HTTP API (do consider the security implications here) or using a pinning service that will let you create IPNS names.