user open up a webpage, run the Helia node, upload user’s content, pin it and content is available across all IPFS network from any client as long as user has open and running the page in the browser.
That’s a fair expectation if all the items previously mentioned are completed. Have you used pl-diagnose to debug problems? Do you have a code example that’s easy to run and test? (on codesandbox, stackblitz, codepen, etc…?)
I extended our script-tag example from the helia-examples repo that lives on codesandbox to:
- Use the latest versions of packages (from npm not script tags)
- show multiaddrs which you can attempt to dial
You can find it at https://codesandbox.io/p/sandbox/helia-script-tag-forked-3q8y35
With this node running from codesandbox in the browser, I could fetch new, unique content created by my Helia browser node, from a local Kubo node. Below are the steps I took, you will need 3 separate windows – one browser window and two terminals(shell prompts) – to complete this exercise.
An exercise in retrieving content from Helia
In your browser
- Open up https://codesandbox.io/p/sandbox/helia-script-tag-forked-3q8y35 and ensure the helia node is running and generates some Multiaddr(s) to connect to
- After you have some multiaddrs created, Copy the multiaddrs listed on the page, and paste to a text file somewhere. For reference in these instructions, we’ll call them
commands.txt
- Prefix EACH line with
npx go-ipfs swarm connect
, they should look something likenpx go-ipfs swarm connect /ip4/###.###.###.###/udp/...
- Prefix EACH line with
- run the following script in your browser console:
const textEncoder = new TextEncoder()
const cid = await heliaFs.addBytes(textEncoder.encode('test-123-YYYY-MM-DD-Other-unique-text-stuff-to-ensure-unique-cid'))
// If you don't create a unique CID, you are not guaranteed to retrieve the data from your Helia node.
console.log('cid', cid.toString())
// note this CID because you will need it.
for await (const event of helia.libp2p.services.dht.provide(cid)) {
console.log(event)
}
- Ensure you copy the CID logged to your console
In a terminal on your machine
- run the following:
npx go-ipfs daemon
In a separate terminal
- paste the commands from
commands.txt
and run them.- You should see a message output like
connect $YOUR_HELIA_PEER_ID success
. If you do not, repeat step 2 from the browser section above to ensure you have the latest multiaddrs, and try again.
- You should see a message output like
- run
npx go-ipfs cat $CID_YOU_COPIED_FROM_THE_BROWSER_CONSOLE
- You should see the unique text string you created in your browser.
At this point, you should also be able to get the same unique text string by visiting any IPFS gateway:
- https://ipfs.io/ipfs/$CID_YOU_COPIED_FROM_THE_BROWSER_CONSOLE
- https://dweb.link/ipfs/$CID_YOU_COPIED_FROM_THE_BROWSER_CONSOLE
- https://$CID_YOU_COPIED_FROM_THE_BROWSER_CONSOLE.ipfs.dweb.link/
Note: if you’re not using a chromium based browser with webtransport support, you probably won’t ever get successful connections, discover more peers, and will likely never be able to generate multiaddrs. e.g. in Safari, the browser Helia node does not connect to anything and because of that, cannot discover new peers. I only get the following errors in the console: WebSocket connection to 'wss://ny5.bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa' failed: The operation couldn’t be completed. Protocol error