### Install @helia/libp2p Source: https://github.com/ipfs/helia/blob/main/packages/libp2p/README.md Use this command to install the @helia/libp2p package in your project. ```bash $ npm i @helia/libp2p ``` -------------------------------- ### Install Trustless Gateway Client Source: https://github.com/ipfs/helia/blob/main/packages/trustless-gateway-client/README.md Install the trustless-gateway-client package using npm. ```console npm i @helia/trustless-gateway-client ``` -------------------------------- ### Install @helia/interop Source: https://github.com/ipfs/helia/blob/main/packages/interop/README.md Install the @helia/interop package using npm. ```bash $ npm i @helia/interop ``` -------------------------------- ### Install @helia/strings Source: https://github.com/ipfs/helia/blob/main/packages/strings/README.md Install the @helia/strings package using npm. ```bash $ npm i @helia/strings ``` -------------------------------- ### Add and Get DAG-JSON with Helia Source: https://github.com/ipfs/helia/blob/main/packages/dag-json/README.md This example demonstrates how to create a Helia node, initialize the dag-json module, add a JSON object, and then retrieve it using its CID. Ensure Helia and @helia/dag-json are installed. ```typescript import { createHelia } from 'helia' import { dagJson } from '@helia/dag-json' import { CID } from 'multiformats/cid' const helia = await createHelia() const j = dagJson(helia) const cid = await j.add({ hello: 'world' }) const obj = await j.get(cid) console.info(obj) // { hello: 'world' } ``` -------------------------------- ### Run Transport Benchmarks Source: https://github.com/ipfs/helia/blob/main/benchmarks/transports/README.md Commands to set up and run the Helia transport benchmarks. Ensure all dependencies are installed and the project is built before starting. ```bash npm run reset npm i npm run build cd benchmarks/transports npm start ``` -------------------------------- ### NPM Start Script Output Source: https://github.com/ipfs/helia/blob/main/benchmarks/gc/README.md The output from running 'npm start' within the gc benchmark directory. It shows the build process and the execution of the benchmark script, including the start of TypeScript compilation and the generation of results. ```bash > benchmarks-gc@1.0.0 start > npm run build && node dist/src/index.js > benchmarks-gc@1.0.0 build > aegir build --bundle false [14:51:28] tsc [started] [14:51:33] tsc [completed] generating Ed25519 keypair... ┌─────────┬────────────────┬─────────┬───────────┬──────┐ │ (index) │ Implementation │ ops/s │ ms/op │ runs │ ├─────────┼────────────────┼─────────┼───────────┼──────┤ //... results here ``` -------------------------------- ### Install @helia/unixfs via npm Source: https://github.com/ipfs/helia/blob/main/packages/unixfs/README.md Standard npm installation command for the @helia/unixfs package. ```bash npm i @helia/unixfs ``` -------------------------------- ### Getting Started with IPNS Publish and Resolve Source: https://github.com/ipfs/helia/blob/main/packages/ipns/README.md Demonstrates basic IPNS operations: publishing data and resolving the associated name. Requires Helia, IPNS, and UnixFS modules. ```typescript import { createHelia } from 'helia' import { ipns } from '@helia/ipns' import { unixfs } from '@helia/unixfs' const helia = await createHelia() const name = ipns(helia) // store some data to publish const fs = unixfs(helia) const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4])) // publish the name const { publicKey } = await name.publish('key-1', cid) // resolve the name for await (const result of name.resolve(publicKey)) { console.info(result.record.value) // /ipfs/QmFoo } ``` -------------------------------- ### Install @helia/delegated-routing-client with npm Source: https://github.com/ipfs/helia/blob/main/packages/delegated-routing-client/README.md Install the package using npm. This is the standard way to add the library to your project for use with Node.js or other JavaScript environments. ```console npm i @helia/delegated-routing-client ``` -------------------------------- ### Build and Run Command Source: https://github.com/ipfs/helia/blob/main/benchmarks/transports/README.md The build and start script for the benchmarks, which first bundles the code using 'aegir build' and then executes the main script. ```bash > benchmarks-transports@1.0.0 start > npm run build && node dist/src/index.js > benchmarks-transports@1.0.0 build > aegir build --bundle false [14:51:28] tsc [started] [14:51:33] tsc [completed] ``` -------------------------------- ### Install @helia/bitswap Source: https://github.com/ipfs/helia/blob/main/packages/bitswap/README.md Use npm to install the @helia/bitswap module. This is the standard way to add the package to your project. ```bash $ npm i @helia/bitswap ``` -------------------------------- ### Install @helia/car package Source: https://github.com/ipfs/helia/blob/main/packages/car/README.md Use this command to install the @helia/car package using npm. ```bash $ npm i @helia/car ``` -------------------------------- ### Install @helia/json via npm Source: https://github.com/ipfs/helia/blob/main/packages/json/README.md Use this command to install the @helia/json package in your project. ```console $ npm i @helia/json ``` -------------------------------- ### Create and Use Mutable File System with Helia Source: https://github.com/ipfs/helia/blob/main/packages/mfs/README.md This example demonstrates how to initialize Helia, access the mutable file system (MFS), create a directory, write a file, and read its content. Ensure Helia is properly set up before using MFS operations. ```typescript import { createHelia } from 'helia' import { mfs } from '@helia/mfs' const helia = await createHelia() const fs = mfs(helia) // create an empty directory await fs.mkdir('/my-directory') // add a file to the directory await fs.writeBytes(Uint8Array.from([0, 1, 2, 3]), '/my-directory/foo.txt') // read the file for await (const buf of fs.cat('/my-directory/foo.txt')) { console.info(buf) } ``` -------------------------------- ### Install @helia/mfs using npm Source: https://github.com/ipfs/helia/blob/main/packages/mfs/README.md Use this command to install the @helia/mfs package in your Node.js project. ```bash $ npm i @helia/mfs ``` -------------------------------- ### Install Helia DNSLink via npm Source: https://github.com/ipfs/helia/blob/main/packages/dnslink/README.md Install the @helia/dnslink package using npm for Node.js projects. ```bash $ npm i @helia/dnslink ``` -------------------------------- ### Test New Kubo Release with Helia Source: https://github.com/ipfs/helia/blob/main/packages/interop/README.md Install the package and run interop tests, specifying the Kubo binary path. ```bash $ npm i @helia/interop $ KUBO_BINARY=/path/to/kubo helia-interop ``` -------------------------------- ### Install @helia/utils with npm Source: https://github.com/ipfs/helia/blob/main/packages/utils/README.md Use this command to add the @helia/utils package to your project's dependencies. ```bash npm i @helia/utils ``` -------------------------------- ### Build and Run Helia Pinning Benchmark Script Source: https://github.com/ipfs/helia/blob/main/benchmarks/pinning/README.md This command builds the project and then executes the main pinning benchmark script. It's part of the npm start script. ```bash > benchmarks-pinning@1.0.0 start > npm run build && node dist/src/index.js ``` -------------------------------- ### Install @helia/fallback-router Source: https://github.com/ipfs/helia/blob/main/packages/fallback-router/README.md Install the package using npm. This command is used to add the fallback-router to your project's dependencies. ```bash npm i @helia/fallback-router ``` -------------------------------- ### Install @helia/dag-json via npm Source: https://github.com/ipfs/helia/blob/main/packages/dag-json/README.md Use this command to install the @helia/dag-json package in your project. ```bash $ npm i @helia/dag-json ``` -------------------------------- ### Benchmark Output Table Source: https://github.com/ipfs/helia/blob/main/benchmarks/add-dir/README.md Example output table from the addDir benchmark, showing performance metrics (ops/s, ms/op, p99) and constructed CIDs for Helia, js-ipfs, and Kubo implementations. ```text ┌─────────┬─────────────────────┬─────────┬───────────┬──────┬───────────┬───────────┐ │ (index) │ Implementation │ ops/s │ ms/op │ runs │ p99 │ CID │ ├─────────┼─────────────────────┼─────────┼───────────┼──────┼───────────┼───────────┤ //... results here └─────────┴─────────────────────┴─────────┴───────────┴──────┴───────────┴───────────┘ ``` -------------------------------- ### Install Helia via npm Source: https://github.com/ipfs/helia/blob/main/packages/helia/README.md Install the Helia package using npm for use in your Node.js projects. ```bash $ npm i helia ``` -------------------------------- ### Get Block Before Streaming Blockstore Source: https://github.com/ipfs/helia/wiki/Upgrade-guide-from-Helia-5.0.0-to-Helia-6.0.0 Before Helia 6.x.x, blocks were retrieved as a whole. This example shows the previous method of fetching a complete block. ```TypeScript import { createHelia } from 'helia' import { CID } from 'multiformats/cid' const helia = await createHelia() const cid = CID.parse('Qmfoo') const block = await helia.blocks.get(cid, { signal: AbortSignal.timeout(5_000) }) // use block ``` -------------------------------- ### Run Helia Pinning Benchmark Source: https://github.com/ipfs/helia/blob/main/benchmarks/pinning/README.md Execute the Helia pinning benchmark. Ensure all prerequisites are met, including adding benchmarks to package.json and installing dependencies. ```bash $ npm run reset $ npm i $ npm run build $ cd benchmarks/pinning $ npm start ``` -------------------------------- ### Get and Put Blocks in Helia Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Shows how to interact with Helia's blockstore directly for getting and putting blocks. ```javascript await helia.blockstore.get(cid) await helia.blockstore.put(cid, buf) // etc ``` -------------------------------- ### Install @helia/interface Source: https://github.com/ipfs/helia/blob/main/packages/interface/README.md Install the @helia/interface package using npm. This command is used to add the Helia interface to your project dependencies. ```bash $ npm i @helia/interface ``` -------------------------------- ### Run GC Benchmark Source: https://github.com/ipfs/helia/blob/main/benchmarks/gc/README.md Execute the GC benchmark script. This involves building the project and then running the main JavaScript file. Ensure all dependencies are installed and the project is built. ```bash npm run reset npm i npm run build cd benchmarks/gc npm start ``` -------------------------------- ### Install @helia/http via npm Source: https://github.com/ipfs/helia/blob/main/packages/http/README.md Install the @helia/http module using npm. This command adds the package to your project's dependencies. ```bash $ npm i @helia/http ``` -------------------------------- ### Install IPNS Package with npm Source: https://github.com/ipfs/helia/blob/main/packages/ipns/README.md Install the @helia/ipns package using npm. This is the standard way to add the package to your project. ```bash $ npm i @helia/ipns ``` -------------------------------- ### Get and Set Configuration in js-IPFS Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Shows how to retrieve and set configuration values using the js-IPFS config API. ```javascript ipfs.config.get('key') ipfs.config.set('key', 'value') // etc ``` -------------------------------- ### Get and Put Blocks in js-IPFS Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Illustrates how to retrieve and store blocks using the js-IPFS block API. ```javascript await ipfs.block.get(cid) await ipfs.block.put(buf) // etc ``` -------------------------------- ### Install @helia/dag-cbor via npm Source: https://github.com/ipfs/helia/blob/main/packages/dag-cbor/README.md Install the @helia/dag-cbor package using npm to add DAG-CBOR capabilities to your Helia project. ```bash $ npm i @helia/dag-cbor ``` -------------------------------- ### Create and Use Helia Node Source: https://github.com/ipfs/helia/blob/main/packages/helia/README.md Initialize a Helia node and use it with the unixfs module to interact with files. Ensure you have the necessary modules installed. ```typescript import { createHelia } from 'helia' import { unixfs } from '@helia/unixfs' import { CID } from 'multiformats/cid' const helia = await createHelia() const fs = unixfs(helia) fs.cat(CID.parse('bafyFoo')) ``` -------------------------------- ### Add and Get JSON with Helia Source: https://github.com/ipfs/helia/blob/main/packages/json/README.md Demonstrates how to create a Helia instance, initialize the JSON module, add a JSON object, and retrieve it using its CID. Ensure Helia and the JSON module are imported. ```typescript import { createHelia } from 'helia' import { json } from '@helia/json' import { CID } from 'multiformats/cid' const helia = await createHelia() const j = json(helia) const cid = await j.add({ hello: 'world' }) const obj = await j.get(cid) console.info(obj) // { hello: 'world' } ``` -------------------------------- ### Create Helia Node with Libp2p Source: https://github.com/ipfs/helia/blob/main/packages/libp2p/README.md This snippet demonstrates how to create a Helia node and enable libp2p functionality. It imports necessary functions from 'helia' and '@helia/libp2p'. The node is then started, and its peer ID is logged to the console. ```typescript import { createHelia } from 'helia' import { withLibp2p } from '@helia/libp2p' const node = await withLibp2p(createHelia()).start() console.info(node.libp2p.peerId) // 12D3Koo... ``` -------------------------------- ### Recursively Add Directory Content with Helia UnixFS Source: https://github.com/ipfs/helia/blob/main/packages/unixfs/README.md Shows how to recursively add the contents of a directory using glob patterns. This example is intended for Node.js-compatible environments. ```typescript import { createHelia } from 'helia' import { unixfs } from '@helia/unixfs' import { globSource } from '@helia/unixfs' const helia = await createHelia() const fs = unixfs(helia) for await (const entry of fs.addAll(globSource('path/to/containing/dir', 'glob-pattern'))) { console.info(entry) } ``` -------------------------------- ### Load Whole Block from Stream Source: https://github.com/ipfs/helia/wiki/Upgrade-guide-from-Helia-5.0.0-to-Helia-6.0.0 To load the entire block from the new streaming API, use the 'it-to-buffer' package. This example shows how to convert the stream to a buffer. ```TypeScript import { createHelia } from 'helia' import { CID } from 'multiformats/cid' import toBuffer from 'it-to-buffer' const helia = await createHelia() const cid = CID.parse('Qmfoo') const block = await toBuffer(helia.blocks.get(cid, { signal: AbortSignal.timeout(5_000) })) // use block ``` -------------------------------- ### Put and Get DAG Objects in js-IPFS Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Illustrates creating and retrieving DAG objects using the js-IPFS DAG API. ```javascript const cid = await ipfs.dag.put({ hello: 'world' }, { storeCodec: 'json' }) const obj = await ipfs.dag.get(cid) // etc ``` -------------------------------- ### Swarm Operations in Helia Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS This snippet demonstrates swarm operations in Helia by invoking methods directly on the `.libp2p` object, including getting multiaddresses and dialing/hanging up. ```js helia.libp2p.getMultiaddrs() await helia.libp2p.dial(multiaddr) await helia.libp2p.hangUp(multiaddr) // etc ``` -------------------------------- ### Dynamically Import Helia from CJS Source: https://github.com/ipfs/helia/wiki/Troubleshooting If you must use Helia from a CommonJS environment, use dynamic imports. This example shows how to load Helia using dynamic import. ```javascript async function main () { const { createHelia } = await import('helia') const helia = await createHelia() } ``` -------------------------------- ### Export CAR File Before Helia 6.x.x Source: https://github.com/ipfs/helia/wiki/Upgrade-guide-from-Helia-5.0.0-to-Helia-6.0.0 This example shows the previous method of exporting CAR files using the .stream method from @helia/car, which required an extra dependency and a CarWriter. ```TypeScript import { createHelia } from 'helia' import { car } from '@helia/car' import { CID } from 'multiformats/cid' import { CarWriter } from '@ipld/car' const helia = await createHelia() const cid = CID.parse('Qmfoo') const c = car(helia) const { writer, out } = await CarWriter.create([cid]) c.export(cid, writer) .catch(err => { // handle err somehow? }) for await (const chunk of out) { // ...do something with chunk } ``` -------------------------------- ### Resolve Domain with DNSLink Entry Source: https://github.com/ipfs/helia/blob/main/packages/dnslink/README.md Resolve a CID from a TXT record in a DNS zone file using the default platform resolver. This example demonstrates resolving 'blog.ipfs.tech'. ```TypeScript // resolve a CID from a TXT record in a DNS zone file, using the default // resolver for the current platform eg: // > dig _dnslink.ipfs.tech TXT // ;; ANSWER SECTION: // _dnslink.ipfs.tech. 60 IN CNAME _dnslink.ipfs-tech.on.fleek.co. // _dnslink.ipfs-tech.on.fleek.co. 120 IN TXT "dnslink=/ipfs/bafybe..." import { createHelia } from 'helia' import { dnsLink } from '@helia/dnslink' const node = await createHelia().start() const name = dnsLink(node) const [{ answer }] = await name.resolve('blog.ipfs.tech') console.info(answer) // { data: '/ipfs/bafybe...' } ``` -------------------------------- ### Create Files and Directories with Helia UnixFS Source: https://github.com/ipfs/helia/blob/main/packages/unixfs/README.md Demonstrates creating an empty directory, adding a file with byte content, and then adding that file to the directory. Also shows an alternative stream-based approach for the same operations. ```typescript import { createHelia } from 'helia' import { unixfs } from '@helia/unixfs' const helia = await createHelia() const fs = unixfs(helia) // create an empty dir and a file, then add the file to the dir const emptyDirCid = await fs.addDirectory() const fileCid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3])) const updateDirCid = await fs.cp(fileCid, emptyDirCid, 'foo.txt') // or doing the same thing as a stream for await (const entry of fs.addAll([{ path: 'foo.txt', content: Uint8Array.from([0, 1, 2, 3]) }])) { console.info(entry) } ``` -------------------------------- ### Get Block Using Streaming Blockstore Source: https://github.com/ipfs/helia/wiki/Upgrade-guide-from-Helia-5.0.0-to-Helia-6.0.0 After Helia 6.x.x, the blockstore returns streams of bytes for a CID, reducing memory usage. This example demonstrates iterating over chunks. ```TypeScript import { createHelia } from 'helia' import { CID } from 'multiformats/cid' const helia = await createHelia() const cid = CID.parse('Qmfoo') for await (const chunk of await helia.blocks.get(cid, { signal: AbortSignal.timeout(5_000) })) { // use chunk } ``` -------------------------------- ### Run addDir Benchmark Source: https://github.com/ipfs/helia/blob/main/benchmarks/add-dir/README.md Execute the addDir benchmark for Helia, js-ipfs, and Kubo. Ensure all prerequisites are met before running. ```bash npm run reset npm i npm run build cd benchmarks/add-dir npm start ``` -------------------------------- ### Build and Run Benchmark Script Source: https://github.com/ipfs/helia/blob/main/benchmarks/add-dir/README.md Builds the benchmark project using 'aegir build' and then executes the main benchmark script with Node.js. ```bash > benchmarks-gc@1.0.0 start > npm run build && node dist/src/index.js > benchmarks-gc@1.0.0 build > aegir build --bundle false ``` -------------------------------- ### Configure Helia Node Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Demonstrates how to pass configuration options directly when creating a Helia node. ```javascript const node = await createHelia({ // config here }) ``` -------------------------------- ### Run Helia Transfer Benchmark Source: https://github.com/ipfs/helia/blob/main/benchmarks/transfer/README.md Commands to set up and run the Helia transfer benchmark. Ensure all prerequisites are met before execution. ```bash $ npm run reset $ npm i $ npm run build $ cd benchmarks/transfer $ npm start > benchmarks-gc@1.0.0 start > npm run build && node dist/src/index.js > benchmarks-transfer@1.0.0 build > aegir build --bundle false [14:51:28] tsc [started] [14:51:33] tsc [completed] generating Ed25519 keypair... ┌─────────┬────────────────┬─────────┬───────────┬──────┐ │ (index) │ Implementation │ ops/s │ ms/op │ runs │ ├─────────┼────────────────┼─────────┼───────────┼──────┤ //... results here ``` -------------------------------- ### Add Files and Directories in the Browser with Helia UnixFS Source: https://github.com/ipfs/helia/blob/main/packages/unixfs/README.md Illustrates how to add files and directories in a browser environment using sources from @cypsela/browser-source. Supports FileList, FileSystemEntry, and FileSystemHandle. ```typescript import { createHelia } from 'helia' import { unixfs } from '@helia/unixfs' import { fileListSource, fsEntrySource, fsHandleSource } from '@cypsela/browser-source' const helia = await createHelia() const fs = unixfs(helia) // get FileList from elements const fileList = {} as FileList for await (const entry of fs.addAll(fileListSource(fileList))) { console.info(entry) } // get FileSystemEntry from drag and drop events const fileEntry = {} as FileSystemEntry for await (const entry of fs.addAll(fsEntrySource(fileEntry))) { console.info(entry) } // get FileSystemHandle from drag and drop events or window methods const fileHandle = {} as FileSystemHandle for await (const entry of fs.addAll(fsHandleSource(fileHandle))) { console.info(entry) } ``` -------------------------------- ### Generate Graph Data for Pinning Benchmark Source: https://github.com/ipfs/helia/blob/main/benchmarks/pinning/README.md Builds the project and then runs the graph generation script for the pinning benchmark results. ```bash $ npm run build && node dist/src/graph.js ``` -------------------------------- ### Build Project with Aegir Source: https://github.com/ipfs/helia/blob/main/benchmarks/pinning/README.md Builds the project using Aegir, disabling bundling for the build process. This is a prerequisite for running the benchmark. ```bash > benchmarks-pinning@1.0.0 build > aegir build --bundle false ``` -------------------------------- ### TypeScript Compilation Output Source: https://github.com/ipfs/helia/blob/main/benchmarks/pinning/README.md Indicates the start and completion of the TypeScript compilation process using tsc. ```log [14:51:28] tsc [started] [14:51:33] tsc [completed] ``` -------------------------------- ### Get Peer ID and Multiaddrs Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS The `ipfs.id()` method in js-IPFS is replaced by accessing `helia.libp2p.peerId` and `helia.libp2p.getMultiaddrs()` in Helia. ```javascript const { id, multiaddrs // etc } = await ipfs.id() ``` ```javascript const id = helia.libp2p.peerId const multiaddrs = helia.libp2p.getMultiaddrs() // etc ``` -------------------------------- ### Import Helia Type Source: https://github.com/ipfs/helia/blob/main/packages/interface/README.md Import the Helia type for use in your TypeScript projects. This is a basic setup for interacting with a Helia node. ```typescript import type { Helia } from '@helia/interface' export function doSomething(helia: Helia) { // use helia node functions here } ``` -------------------------------- ### Create and Stop a js-IPFS Node Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Demonstrates the basic lifecycle of a js-IPFS node, including creation and stopping. ```javascript import { create } from 'ipfs-core' const ipfs = await create() // the node is running await ipfs.stop() // the node is stopped ``` -------------------------------- ### Configure and Use DHT in Helia Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Shows how to configure and access the DHT service via the libp2p object in Helia. ```javascript import { createHelia } from 'helia' import { createLibp2p } from 'libp2p' import { kadDHT } from '@libp2p/kad-dht' const helia = await createHelia({ libp2p: createLibp2p({ //... other libp2p config services: { dht: kadDHT() } }) }) for await (const event of helia.libp2p.services.dht.findPeer(peerId)) { // etc } ``` -------------------------------- ### Change Benchmark Iterations Source: https://github.com/ipfs/helia/blob/main/benchmarks/add-dir/README.md Modify the number of iterations for the benchmark by setting the ITERATIONS environment variable. This example sets it to 1. ```bash ITERATIONS=1 npm start ``` -------------------------------- ### Test Helia Benchmarks with neo-async Source: https://github.com/ipfs/helia/blob/main/benchmarks/add-dir/README.md Configure the TEST_PATH environment variable to point to the 'neo-async' module within node_modules to test its integration. ```bash TEST_PATH=../../node_modules/neo-async npm start > benchmarks-add-dir@1.0.0 start > npm run build && node dist/src/index.js > benchmarks-add-dir@1.0.0 build > aegir build --bundle false [13:31:27] tsc [started] [13:31:28] tsc [completed] generating Ed25519 keypair... (node:34722) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time (Use `node --trace-warnings ...` to show where the warning was created) ┌─────────┬──────────────────────────────────────────────┬─────────┬───────────┬──────┬───────────┬───────────┐ │ (index) │ Implementation │ ops/s │ ms/op │ runs │ p99 │ CID │ ├─────────┼──────────────────────────────────────────────┼─────────┼───────────┼──────┼───────────┼───────────┤ │ 0 │ 'helia-fs - ../../node_modules/neo-async' │ '2.01' │ '498.48' │ 5 │ '2190.31' │ 'bafyfoo' │ │ 1 │ 'helia-mem - ../../node_modules/neo-async' │ '19.22' │ '52.04' │ 5 │ '85.31' │ 'bafyfoo' │ │ 2 │ 'ipfs - ../../node_modules/neo-async' │ '0.20' │ '4895.68' │ 5 │ '5209.99' │ 'bafyfoo' │ │ 3 │ 'kubo - ../../node_modules/neo-async' │ '0.38' │ '2641.59' │ 5 │ '7776.20' │ 'bafyfoo' │ │ 4 │ 'kubo-direct - ../../node_modules/neo-async' │ '0.43' │ '2348.51' │ 5 │ '7149.77' │ 'bafyfoo' │ └─────────┴──────────────────────────────────────────────┴─────────┴───────────┴──────┴───────────┴───────────┘ ``` -------------------------------- ### Key Management Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Key generation and listing are accessed via `ipfs.key` in js-IPFS and `helia.libp2p.keychain` in Helia. ```javascript await ipfs.key.gen('my-key') await ipfs.key.list() // etc ``` ```javascript await helia.libp2p.keychain.createKey('my-key') await helia.libp2p.keychain.listKeys() // etc ``` -------------------------------- ### Configure Bootstrap Peers in Helia Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Illustrates configuring bootstrap peers directly within the libp2p settings when creating a Helia node. ```javascript const node = await createHelia({ libp2p: createLibp2p({ // ..other settings peerDiscovery: [ bootstrap({ list: [ '/dnsaddr/bootstrap.io/p2p/QmBootstrap1', '/dnsaddr/bootstrap.io/p2p/QmBootstrap2' // etc ] }) ] }) }) ``` -------------------------------- ### Build and Run Graph Script Source: https://github.com/ipfs/helia/blob/main/benchmarks/gc/README.md Build the project and then execute the graph script to output statistics for graphing. This command is used after the main benchmark has been run or for specific graph-related data generation. ```bash npm run build && node dist/src/graph.js ``` -------------------------------- ### Add and Get DAG Objects in Helia using @helia/json Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Shows how to add and retrieve JSON data using the @helia/json module, replacing the js-IPFS DAG API. ```javascript import { json } from '@helia/json' const j = json(helia) const cid = await j.add({ hello: 'world' }) const obj = await j.get(cid) // etc ``` -------------------------------- ### Add and Get Strings with Helia Source: https://github.com/ipfs/helia/blob/main/packages/strings/README.md Use this snippet to add a string to your Helia node and then retrieve it using its CID. Ensure Helia is created and the strings module is imported. ```typescript import { createHelia } from 'helia' import { strings } from '@helia/strings' import { CID } from 'multiformats/cid' const helia = await createHelia() const str = strings(helia) const cid = await str.add('hello world') const string = await str.get(cid) console.info(string) // hello world ``` -------------------------------- ### Add and Get JSON with Helia Source: https://github.com/ipfs/helia/blob/main/README.md Utilize the @helia/json module for adding and retrieving plain JavaScript objects from your Helia node. Requires Helia and the JSON module to be initialized. ```javascript import { createHelia } from 'helia' import { json } from '@helia/json' const helia = await createHelia() const j = json(helia) const myImmutableAddress = await j.add({ hello: 'world' }) console.log(await j.get(myImmutableAddress)) // { hello: 'world' } ``` -------------------------------- ### Add and Get Strings with Helia Source: https://github.com/ipfs/helia/blob/main/README.md Use the @helia/strings module to add and retrieve string data from your Helia node. Ensure the Helia node and strings module are initialized. ```javascript import { createHelia } from 'helia' import { strings } from '@helia/strings' const helia = await createHelia() const s = strings(helia) const myImmutableAddress = await s.add('hello world') console.log(await s.get(myImmutableAddress)) // hello world ``` -------------------------------- ### Benchmark Results with Custom Iterations Source: https://github.com/ipfs/helia/blob/main/benchmarks/add-dir/README.md Displays benchmark results after setting the ITERATIONS environment variable to 1. Includes performance metrics and CIDs for various implementations. ```text ┌─────────┬───────────────────────────┬──────────┬──────────┬──────┬───────────┬───────────┐ │ (index) │ Implementation │ ops/s │ ms/op │ runs │ p99 │ CID │ ├─────────┼───────────────────────────┼──────────┼──────────┼──────┼───────────┼───────────┤ │ 0 │ 'helia-fs - src' │ '438.44' │ '2.28' │ 439 │ '3.97' │ 'bafyfoo' │ │ 1 │ 'helia-fs - dist' │ '81.62' │ '12.25' │ 82 │ '316.61' │ 'bafyfoo' │ │ 2 │ 'helia-fs - ../gc/src' │ '475.87' │ '2.10' │ 476 │ '5.59' │ 'bafyfoo' │ │ 3 │ 'helia-mem - src' │ '924.29' │ '1.08' │ 925 │ '2.08' │ 'bafyfoo' │ │ 4 │ 'helia-mem - dist' │ '242.95' │ '4.12' │ 243 │ '5.92' │ 'bafyfoo' │ │ 5 │ 'helia-mem - ../gc/src' │ '901.17' │ '1.11' │ 902 │ '2.70' │ 'bafyfoo' │ │ 6 │ 'ipfs - src' │ '11.60' │ '86.22' │ 12 │ '103.93' │ 'bafyfoo' │ │ 7 │ 'ipfs - dist' │ '2.29' │ '436.19' │ 5 │ '456.56' │ 'bafyfoo' │ │ 8 │ 'ipfs - ../gc/src' │ '6.11' │ '163.68' │ 7 │ '181.44' │ 'bafyfoo' │ │ 9 │ 'kubo - src' │ '13.78' │ '72.56' │ 14 │ '248.15' │ 'bafyfoo' │ │ 10 │ 'kubo - dist' │ '2.50' │ '400.71' │ 5 │ '1208.74' │ 'bafyfoo' │ │ 11 │ 'kubo - ../gc/src' │ '11.79' │ '84.79' │ 12 │ '433.94' │ 'bafyfoo' │ │ 12 │ 'kubo-direct - src' │ '14.68' │ '68.13' │ 15 │ '240.11' │ 'bafyfoo' │ │ 13 │ 'kubo-direct - dist' │ '2.48' │ '403.53' │ 5 │ '1232.42' │ 'bafyfoo' │ │ 14 │ 'kubo-direct - ../gc/src' │ '13.89' │ '71.99' │ 14 │ '329.82' │ 'bafyfoo' │ └─────────┴───────────────────────────┴──────────┴──────────┴──────┴───────────┴───────────┘ ``` -------------------------------- ### Add and List Pins in js-IPFS Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Use this snippet for adding and listing pinned content with js-IPFS. Ensure the IPFS instance is properly initialized. ```js await ipfs.pin.add(cid) await ipfs.pin.ls() // etc ``` -------------------------------- ### Run Helia Benchmarks with Custom Time Source: https://github.com/ipfs/helia/blob/main/benchmarks/add-dir/README.md Set the MIN_TIME environment variable to control the duration of the benchmark test, allowing for more iterations. ```bash MIN_TIME=1000 npm start > benchmarks-add-dir@1.0.0 start > npm run build && node dist/src/index.js > benchmarks-add-dir@1.0.0 build > aegir build --bundle false [13:00:38] tsc [started] [13:00:39] tsc [completed] generating Ed25519 keypair... (node:13367) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time (Use `node --trace-warnings ...` to show where the warning was created) generating Ed25519 keypair... generating Ed25519 keypair... ┌─────────┬─────────────────────┬──────────┬──────────┬──────┬───────────┬───────────┐ │ (index) │ Implementation │ ops/s │ ms/op │ runs │ p99 │ CID │ ├─────────┼─────────────────────┼──────────┼──────────┼──────┼───────────┼───────────┤ │ 0 │ 'helia - src' │ '516.16' │ '1.94' │ 517 │ '3.47' │ 'bafyfoo' │ │ 1 │ 'helia - dist' │ '126.64' │ '7.90' │ 127 │ '13.49' │ 'bafyfoo' │ │ 2 │ 'helia - ../gc/src' │ '502.72' │ '1.99' │ 503 │ '3.66' │ 'bafyfoo' │ │ 3 │ 'ipfs - src' │ '13.12' │ '76.22' │ 14 │ '99.63' │ 'bafyfoo' │ │ 4 │ 'ipfs - dist' │ '2.84' │ '352.04' │ 5 │ '418.21' │ 'bafyfoo' │ │ 5 │ 'ipfs - ../gc/src' │ '5.39' │ '185.56' │ 6 │ '217.48' │ 'bafyfoo' │ │ 6 │ 'kubo - src' │ '17.47' │ '57.23' │ 18 │ '208.40' │ 'bafyfoo' │ │ 7 │ 'kubo - dist' │ '3.04' │ '328.87' │ 5 │ '1038.24' │ 'bafyfoo' │ │ 8 │ 'kubo - ../gc/src' │ '12.88' │ '77.65' │ 13 │ '328.25' │ 'bafyfoo' │ └─────────┴─────────────────────┴──────────┴──────────┴──────┴───────────┴───────────┘ ``` -------------------------------- ### Add and Get DAG-CBOR Blocks with Helia Source: https://github.com/ipfs/helia/blob/main/packages/dag-cbor/README.md Use this snippet to add an object as a DAG-CBOR block to your Helia node and then retrieve it using its CID. Ensure Helia and the @helia/dag-cbor module are imported. ```typescript import { createHelia } from 'helia' import { dagCbor } from '@helia/dag-cbor' import { CID } from 'multiformats/cid' const helia = await createHelia() const d = dagCbor(helia) const cid = await d.add({ hello: 'world' }) const obj = await d.get(cid) console.info(obj) // { hello: 'world' } ``` -------------------------------- ### Test Helia Benchmarks with ipfs-core node_modules Source: https://github.com/ipfs/helia/blob/main/benchmarks/add-dir/README.md Set TEST_PATH to target the 'ipfs-core/node_modules' directory to evaluate performance with dependencies from ipfs-core. ```bash TEST_PATH=../../node_modules/ipfs-core/node_modules npm start > benchmarks-add-dir@1.0.0 start > npm run build && node dist/src/index.js > benchmarks-add-dir@1.0.0 build > aegir build --bundle false [14:17:29] tsc [started] [14:17:30] tsc [completed] generating Ed25519 keypair... (node:65964) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time (Use `node --trace-warnings ...` to show where the warning was created) generating Ed25519 keypair... generating Ed25519 keypair... ┌─────────┬───────────────────────────────────────────────────────────┬────────┬─────────────┬──────┬─────────────┬───────────┐ │ (index) │ Implementation │ ops/s │ ms/op │ runs │ p99 │ CID │ ├─────────┼───────────────────────────────────────────────────────────┼────────┼─────────────┼──────┼─────────────┼───────────┤ │ 0 │ 'helia - ../../node_modules/ipfs-core/node_modules' │ '0.15' │ '6708.96' │ 5 │ '29599.11' │ 'bafyfoo' │ │ 1 │ 'ipfs - ../../node_modules/ipfs-core/node_modules' │ '0.00' │ '228866.62' │ 5 │ '237419.96' │ 'bafyfoo' │ │ 2 │ 'kubo - ../../node_modules/ipfs-core/node_modules' │ '0.00' │ '230310.82' │ 5 │ '234432.20' │ 'bafyfoo' │ │ 3 │ 'kubo-direct - ../../node_modules/ipfs-core/node_modules' │ '0.00' │ '205561.86' │ 5 │ '219400.15' │ 'bafyfoo' │ └─────────┴───────────────────────────────────────────────────────────┴────────┴─────────────┴──────┴─────────────┴───────────┘ ``` -------------------------------- ### Load Trustless Gateway Client in Browser Source: https://github.com/ipfs/helia/blob/main/packages/trustless-gateway-client/README.md Load the trustless-gateway-client using a script tag to make it available as a global variable. ```html ``` -------------------------------- ### Export CAR File After Helia 6.x.x Source: https://github.com/ipfs/helia/wiki/Upgrade-guide-from-Helia-5.0.0-to-Helia-6.0.0 The .stream method in @helia/car has been renamed to .export and simplified. This example shows the new, more straightforward way to export CAR files, returning an AsyncGenerator directly. ```TypeScript import { createHelia } from 'helia' import { car } from '@helia/car' import { CID } from 'multiformats/cid' const helia = await createHelia() const cid = CID.parse('Qmfoo') const c = car(helia) for await (const chunk of c.export(cid)) { // ...do something with chunk } ``` -------------------------------- ### Find Peer and Find Providers in js-IPFS DHT Source: https://github.com/ipfs/helia/wiki/Migrating-from-js-IPFS Demonstrates DHT operations like finding peers and providers using the js-IPFS DHT API. ```javascript await ipfs.dht.findPeer(peerId) await ipfs.dht.findProvs(cid) // etc ``` -------------------------------- ### Add and Get DAG-JSON with Helia Source: https://github.com/ipfs/helia/blob/main/README.md Store and retrieve linked objects using DAG-JSON with the @helia/dag-json module. This module allows storing references to other objects as CIDs. Ensure Helia and the DAG-JSON module are initialized. ```javascript import { createHelia } from 'helia' import { dagJson } from '@helia/dag-json' const helia = await createHelia() const d = dagJson(helia) const object1 = { hello: 'world' } const myImmutableAddress1 = await d.add(object1) const object2 = { link: myImmutableAddress1 } const myImmutableAddress2 = await d.add(object2) const retrievedObject = await d.get(myImmutableAddress2) console.log(retrievedObject) // { link: CID(baguqeerasor...) } console.log(await d.get(retrievedObject.link)) // { hello: 'world' } ``` -------------------------------- ### Include traversal path above root in CAR export Source: https://github.com/ipfs/helia/blob/main/packages/car/README.md This example demonstrates how to include blocks that are part of the traversal path but are above the specified export root in the resulting CAR file. Set `includeTraversalBlocks` to `true` to enable this behavior. ```typescript import { createHelia } from 'helia' import { car, UnixFSPath } from '@helia/car' import { CID } from 'multiformats/cid' import nodeFs from 'node:fs' const helia = await createHelia() const parent = CID.parse('QmFoo...') const baz = CID.parse('QmBar...') const c = car(helia) const out = nodeFs.createWriteStream('example.car') for await (const buf of c.export(baz, { signal: AbortSignal.timeout(5_000), traversal: new UnixFSPath(parent, '/foo/bar/baz.txt'), includeTraversalBlocks: true })) { out.write(buf) } out.end() ``` -------------------------------- ### Add and Get DAG-CBOR with Helia Source: https://github.com/ipfs/helia/blob/main/README.md Work with linked objects using Concise Binary Object Representation (CBOR) via the @helia/dag-cbor module. Similar to DAG-JSON, it stores references as CIDs. Helia and the DAG-CBOR module must be initialized. ```javascript import { createHelia } from 'helia' import { dagCbor } from '@helia/dag-cbor' const helia = await createHelia() const d = dagCbor(helia) const object1 = { hello: 'world' } const myImmutableAddress1 = await d.add(object1) const object2 = { link: myImmutableAddress1 } const myImmutableAddress2 = await d.add(object2) const retrievedObject = await d.get(myImmutableAddress2) console.log(retrievedObject) // { link: CID(baguqeerasor...) } console.log(await d.get(retrievedObject.link)) // { hello: 'world' } ``` -------------------------------- ### Import all blocks from a CAR file Source: https://github.com/ipfs/helia/blob/main/packages/car/README.md This snippet shows how to import all blocks from a CAR file into Helia's blockstore. It requires creating a Helia instance, reading the CAR file into a stream, and then using the `c.import` method. An AbortSignal can be provided for timeouts. ```typescript import { createHelia } from 'helia' import { unixfs } from '@helia/unixfs' import { car } from '@helia/car' import { CarReader } from '@ipld/car' import { Readable } from 'node:stream' import nodeFs from 'node:fs' const helia = await createHelia({ // ... helia config }) // import the car const inStream = nodeFs.createReadStream('example.car') const reader = await CarReader.fromIterable(inStream) const c = car(helia) await c.import(reader, { signal: AbortSignal.timeout(5_000) }) ``` -------------------------------- ### Load Helia Interop in Browser Source: https://github.com/ipfs/helia/blob/main/packages/interop/README.md Load the Helia Interop module using a script tag in an HTML file. This makes the exports available as `HeliaInterop` in the global namespace. ```html ```