├── examples ├── helia-nestjs │ ├── .prettierrc │ ├── tsconfig.build.json │ ├── nest-cli.json │ ├── src │ │ ├── app.module.ts │ │ ├── main.ts │ │ ├── app.controller.ts │ │ ├── app.service.ts │ │ └── app.controller.spec.ts │ ├── test │ │ ├── jest-e2e.json │ │ └── app.e2e-spec.ts │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── tsconfig.json │ ├── .eslintrc.cjs │ ├── package.json │ └── README.md ├── helia-esbuild │ ├── img │ │ ├── 1.png │ │ └── 2.png │ ├── esbuild.js │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── package.json │ ├── src │ │ ├── style.css │ │ ├── index.html │ │ └── index.js │ ├── test │ │ └── index.spec.js │ └── README.md ├── helia-parcel │ ├── img │ │ ├── 1.png │ │ └── 2.png │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── package.json │ ├── src │ │ ├── style.css │ │ ├── index.html │ │ └── index.js │ ├── test │ │ └── index.spec.js │ └── README.md ├── helia-webpack │ ├── img │ │ └── 1.png │ ├── src │ │ ├── index.js │ │ ├── app.css │ │ ├── ipfs-logo.svg │ │ └── app.js │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── public │ │ └── index.html │ ├── test │ │ └── index.spec.js │ ├── package.json │ ├── README.md │ └── webpack.config.js ├── helia-vue │ ├── public │ │ └── demo-vue.gif │ ├── src │ │ ├── main.js │ │ ├── assets │ │ │ ├── logo.svg │ │ │ ├── main.css │ │ │ └── base.css │ │ ├── plugins │ │ │ └── HeliaProviderPlugin.js │ │ ├── components │ │ │ ├── TextCommiter.vue │ │ │ └── UnixFSManager.vue │ │ ├── HeliaApi │ │ │ ├── useCommitText.js │ │ │ └── useUnixFS.js │ │ └── App.vue │ ├── vite.config.js │ ├── index.html │ ├── .gitignore │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── package.json │ ├── test │ │ └── index.spec.js │ └── README.md ├── helia-101 │ ├── .gitignore │ ├── test │ │ └── index.spec.js │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── package.json │ ├── 101-basics.js │ ├── 201-storage.js │ └── 301-networking.js ├── helia-cjs │ ├── .gitignore │ ├── test │ │ └── index.spec.mjs │ ├── package.json │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ └── index.js ├── helia-vite │ ├── public │ │ ├── hello-helia.gif │ │ └── vite.svg │ ├── src │ │ ├── hooks │ │ │ ├── useHelia.jsx │ │ │ └── useCommitText.jsx │ │ ├── main.jsx │ │ ├── App.css │ │ ├── index.css │ │ ├── App.jsx │ │ └── provider │ │ │ └── HeliaProvider.jsx │ ├── vite.config.js │ ├── .gitignore │ ├── index.html │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── package.json │ └── test │ │ └── index.spec.js ├── helia-electron │ ├── .gitignore │ ├── helia.mjs │ ├── renderer.js │ ├── test │ │ └── index.spec.mjs │ ├── index.html │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── package.json │ ├── main.js │ └── README.md ├── helia-script-tag │ ├── .gitignore │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── package.json │ ├── test │ │ └── index.spec.js │ ├── vite.config.js │ └── src │ │ └── index.js ├── helia-typescript │ ├── .gitignore │ ├── src │ │ └── index.ts │ ├── test │ │ └── index.spec.js │ ├── tsconfig.json │ ├── package.json │ └── .github │ │ ├── workflows │ │ └── sync.yml │ │ └── pull_request_template.md ├── helia-create-car │ ├── public │ │ ├── helia-create-car-demo.gif │ │ └── vite.svg │ ├── src │ │ ├── hooks │ │ │ ├── useFiles.js │ │ │ └── useHelia.jsx │ │ ├── main.jsx │ │ ├── App.css │ │ ├── provider │ │ │ ├── FileProvider.jsx │ │ │ └── HeliaProvider.jsx │ │ ├── App.jsx │ │ ├── components │ │ │ ├── FileUploader.jsx │ │ │ └── CarCreator.jsx │ │ └── index.css │ ├── vite.config.js │ ├── .gitignore │ ├── index.html │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── package.json │ ├── test │ │ └── index.spec.js │ └── README.md ├── helia-jest │ ├── jest.config.json │ ├── src │ │ └── index.js │ ├── package.json │ ├── test │ │ └── index.spec.js │ └── .github │ │ ├── workflows │ │ └── sync.yml │ │ └── pull_request_template.md ├── helia-nextjs │ ├── next.config.js │ ├── pages │ │ ├── api │ │ │ └── hello.js │ │ ├── _app.js │ │ └── index.js │ ├── styles │ │ ├── globals.css │ │ └── Home.module.css │ ├── .github │ │ ├── workflows │ │ │ └── sync.yml │ │ └── pull_request_template.md │ ├── test │ │ └── index.spec.js │ ├── package.json │ ├── components │ │ └── ipfs.js │ └── public │ │ └── vercel.svg ├── helia-ts-node │ ├── src │ │ └── index.ts │ ├── test │ │ └── index.spec.js │ ├── tsconfig.json │ ├── package.json │ └── .github │ │ ├── workflows │ │ └── sync.yml │ │ └── pull_request_template.md └── helia-jest-typescript │ ├── src │ └── index.ts │ ├── tsconfig.json │ ├── jest.config.json │ ├── package.json │ ├── test │ └── index.spec.ts │ └── .github │ ├── workflows │ └── sync.yml │ └── pull_request_template.md ├── .github ├── dependabot.yml └── workflows │ └── ci.yml ├── .gitignore └── package.json /examples/helia-nestjs/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "singleQuote": true, 3 | "trailingComma": "all" 4 | } -------------------------------------------------------------------------------- /examples/helia-esbuild/img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darobin/helia-examples/main/examples/helia-esbuild/img/1.png -------------------------------------------------------------------------------- /examples/helia-esbuild/img/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darobin/helia-examples/main/examples/helia-esbuild/img/2.png -------------------------------------------------------------------------------- /examples/helia-parcel/img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darobin/helia-examples/main/examples/helia-parcel/img/1.png -------------------------------------------------------------------------------- /examples/helia-parcel/img/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darobin/helia-examples/main/examples/helia-parcel/img/2.png -------------------------------------------------------------------------------- /examples/helia-webpack/img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darobin/helia-examples/main/examples/helia-webpack/img/1.png -------------------------------------------------------------------------------- /examples/helia-vue/public/demo-vue.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darobin/helia-examples/main/examples/helia-vue/public/demo-vue.gif -------------------------------------------------------------------------------- /examples/helia-101/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | .docs 5 | .coverage 6 | node_modules 7 | package-lock.json 8 | yarn.lock 9 | -------------------------------------------------------------------------------- /examples/helia-cjs/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | .docs 5 | .coverage 6 | node_modules 7 | package-lock.json 8 | yarn.lock 9 | -------------------------------------------------------------------------------- /examples/helia-vite/public/hello-helia.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darobin/helia-examples/main/examples/helia-vite/public/hello-helia.gif -------------------------------------------------------------------------------- /examples/helia-electron/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | .docs 5 | .coverage 6 | node_modules 7 | package-lock.json 8 | yarn.lock 9 | -------------------------------------------------------------------------------- /examples/helia-script-tag/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | .docs 5 | .coverage 6 | node_modules 7 | package-lock.json 8 | yarn.lock 9 | -------------------------------------------------------------------------------- /examples/helia-typescript/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | .docs 5 | .coverage 6 | node_modules 7 | package-lock.json 8 | yarn.lock 9 | -------------------------------------------------------------------------------- /examples/helia-nestjs/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "exclude": ["node_modules", "test", "dist", "**/*spec.ts"] 4 | } 5 | -------------------------------------------------------------------------------- /examples/helia-create-car/public/helia-create-car-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darobin/helia-examples/main/examples/helia-create-car/public/helia-create-car-demo.gif -------------------------------------------------------------------------------- /examples/helia-jest/jest.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": [ 3 | "js", 4 | "json" 5 | ], 6 | "rootDir": "test", 7 | "testRegex": ".*\\.spec\\.js$" 8 | } 9 | -------------------------------------------------------------------------------- /examples/helia-nextjs/next.config.js: -------------------------------------------------------------------------------- 1 | export default { 2 | reactStrictMode: true, 3 | images: { 4 | loader: 'imgix', 5 | path: 'http://localhost:3000' 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/helia-jest/src/index.js: -------------------------------------------------------------------------------- 1 | import { createHelia } from 'helia' 2 | 3 | export async function createHeliaNode () { 4 | const node = await createHelia() 5 | 6 | return node 7 | } 8 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "11:00" 8 | open-pull-requests-limit: 50 9 | -------------------------------------------------------------------------------- /examples/helia-electron/helia.mjs: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { createHelia } from 'helia' 4 | 5 | export async function createNode () { 6 | return await createHelia() 7 | } 8 | -------------------------------------------------------------------------------- /examples/helia-electron/renderer.js: -------------------------------------------------------------------------------- 1 | // This file is required by the index.html file and will 2 | // be executed in the renderer process for that window. 3 | // All of the Node.js APIs are available in this process. 4 | -------------------------------------------------------------------------------- /examples/helia-nextjs/pages/api/hello.js: -------------------------------------------------------------------------------- 1 | // Next.js API route support: https://nextjs.org/docs/api-routes/introduction 2 | 3 | export default function handler (req, res) { 4 | res.status(200).json({ name: 'John Doe' }) 5 | } 6 | -------------------------------------------------------------------------------- /examples/helia-nestjs/nest-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/nest-cli", 3 | "collection": "@nestjs/schematics", 4 | "sourceRoot": "src", 5 | "compilerOptions": { 6 | "deleteOutDir": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | dist 4 | .docs 5 | .coverage 6 | node_modules 7 | package-lock.json 8 | yarn.lock 9 | .DS_Store 10 | .next 11 | .vscode 12 | test-results 13 | playwright-report 14 | .parcel-cache 15 | .envrc 16 | .tool-versions 17 | -------------------------------------------------------------------------------- /examples/helia-ts-node/src/index.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { createHelia } from 'helia' 4 | 5 | const node = await createHelia() 6 | 7 | console.info('Helia is running') 8 | console.info('PeerId:', node.libp2p.peerId.toString()) 9 | -------------------------------------------------------------------------------- /examples/helia-jest-typescript/src/index.ts: -------------------------------------------------------------------------------- 1 | import { createHelia } from 'helia' 2 | import type { Helia } from '@helia/interface' 3 | 4 | export async function createHeliaNode (): Promise { 5 | const node = await createHelia() 6 | 7 | return node 8 | } 9 | -------------------------------------------------------------------------------- /examples/helia-create-car/src/hooks/useFiles.js: -------------------------------------------------------------------------------- 1 | import { useContext } from 'react' 2 | import { FileContext } from '../provider/FileProvider' 3 | 4 | export const useFiles = () => { 5 | const { files, setFiles } = useContext(FileContext) 6 | return { files, setFiles } 7 | } 8 | -------------------------------------------------------------------------------- /examples/helia-typescript/src/index.ts: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { createHelia } from 'helia' 4 | 5 | void createHelia() 6 | .then(helia => { 7 | console.info('Helia is running') 8 | console.info('PeerId:', helia.libp2p.peerId.toString()) 9 | }) 10 | -------------------------------------------------------------------------------- /examples/helia-vite/src/hooks/useHelia.jsx: -------------------------------------------------------------------------------- 1 | import { useContext } from 'react' 2 | import { HeliaContext } from '@/provider/HeliaProvider' 3 | 4 | export const useHelia = () => { 5 | const { helia, fs, error, starting } = useContext(HeliaContext) 6 | return { helia, fs, error, starting } 7 | } 8 | -------------------------------------------------------------------------------- /examples/helia-webpack/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { createRoot } from 'react-dom/client' 3 | import './app.css' 4 | import App from './app.js' 5 | 6 | const container = document.getElementById('root') 7 | const root = createRoot(container) 8 | root.render() 9 | -------------------------------------------------------------------------------- /examples/helia-create-car/src/hooks/useHelia.jsx: -------------------------------------------------------------------------------- 1 | import { useContext } from 'react' 2 | import { HeliaContext } from '@/provider/HeliaProvider' 3 | 4 | export const useHelia = () => { 5 | const { helia, fs, error, starting } = useContext(HeliaContext) 6 | return { helia, fs, error, starting } 7 | } 8 | -------------------------------------------------------------------------------- /examples/helia-vue/src/main.js: -------------------------------------------------------------------------------- 1 | import { createApp } from 'vue' 2 | import { HeliaProviderPlugin } from './plugins/HeliaProviderPlugin' 3 | import App from '@/App.vue' 4 | 5 | import './assets/main.css' 6 | 7 | const app = createApp(App) 8 | app.use(HeliaProviderPlugin) 9 | app.mount('#app') 10 | -------------------------------------------------------------------------------- /examples/helia-vue/src/assets/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /examples/helia-electron/test/index.spec.mjs: -------------------------------------------------------------------------------- 1 | import { waitForOutput } from 'test-ipfs-example/node' 2 | import path from 'path' 3 | import { fileURLToPath } from 'url' 4 | 5 | const __dirname = path.dirname(fileURLToPath(import.meta.url)) 6 | 7 | await waitForOutput('PeerId', 'electron', [path.resolve(`${__dirname}/../main.js`)]) 8 | -------------------------------------------------------------------------------- /examples/helia-nestjs/src/app.module.ts: -------------------------------------------------------------------------------- 1 | import { Module } from '@nestjs/common'; 2 | import { AppController } from './app.controller.js'; 3 | import { AppService } from './app.service.js'; 4 | 5 | @Module({ 6 | imports: [], 7 | controllers: [AppController], 8 | providers: [AppService], 9 | }) 10 | export class AppModule {} 11 | -------------------------------------------------------------------------------- /examples/helia-typescript/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import { fileURLToPath } from 'url' 3 | import { waitForOutput } from 'test-ipfs-example/node' 4 | 5 | const __dirname = path.dirname(fileURLToPath(import.meta.url)) 6 | 7 | await waitForOutput('Helia is running', 'node', [path.resolve(__dirname, '../dist/index.js')]) 8 | -------------------------------------------------------------------------------- /examples/helia-cjs/test/index.spec.mjs: -------------------------------------------------------------------------------- 1 | import { waitForOutput } from 'test-ipfs-example/node' 2 | import path from 'path' 3 | import { fileURLToPath } from 'url' 4 | 5 | const __dirname = path.dirname(fileURLToPath(import.meta.url)) 6 | 7 | await waitForOutput('Added file contents: Hello World 101', 'node', [path.resolve(__dirname, '../index.js')]) 8 | -------------------------------------------------------------------------------- /examples/helia-ts-node/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import { fileURLToPath } from 'url' 3 | import { waitForOutput } from 'test-ipfs-example/node' 4 | 5 | const __dirname = path.dirname(fileURLToPath(import.meta.url)) 6 | 7 | await waitForOutput('Helia is running', 'ts-node', ['--esm', path.resolve(__dirname, '../src/index.ts')]) 8 | -------------------------------------------------------------------------------- /examples/helia-vite/vite.config.js: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import react from '@vitejs/plugin-react' 3 | import { defineConfig } from 'vite' 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | resolve: { 8 | alias: [{ find: '@', replacement: path.resolve(__dirname, '/src') }] 9 | } 10 | }) 11 | -------------------------------------------------------------------------------- /examples/helia-create-car/vite.config.js: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import react from '@vitejs/plugin-react' 3 | import { defineConfig } from 'vite' 4 | // https://vitejs.dev/config/ 5 | export default defineConfig({ 6 | plugins: [react()], 7 | resolve: { 8 | alias: [{ find: '@', replacement: path.resolve(__dirname, '/src') }] 9 | } 10 | }) 11 | -------------------------------------------------------------------------------- /examples/helia-ts-node/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ES2022", 4 | "target": "ES2021", 5 | "moduleResolution": "node", 6 | 7 | // only necessary for the example linting check, your project may not need 8 | // these settings 9 | "strictNullChecks": true, 10 | "skipLibCheck": true 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/helia-jest-typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ES2022", 4 | "target": "ES2021", 5 | "moduleResolution": "node", 6 | 7 | // only necessary for the example linting check, your project may not need 8 | // these settings 9 | "strictNullChecks": true, 10 | "skipLibCheck": true 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /examples/helia-esbuild/esbuild.js: -------------------------------------------------------------------------------- 1 | import { build } from 'esbuild' 2 | 3 | build({ 4 | entryPoints: ['./src/index.js'], 5 | outfile: './dist/index.js', 6 | sourcemap: 'linked', 7 | minify: true, 8 | bundle: true, 9 | define: { 10 | 'process.env.NODE_DEBUG': 'false', 11 | global: 'globalThis' 12 | } 13 | }) 14 | .catch(() => process.exit(1)) 15 | -------------------------------------------------------------------------------- /examples/helia-nextjs/pages/_app.js: -------------------------------------------------------------------------------- 1 | import PropTypes from 'prop-types' 2 | import { React } from 'react' 3 | import '../styles/globals.css' 4 | 5 | function MyApp ({ Component, pageProps }) { 6 | return 7 | } 8 | 9 | MyApp.propTypes = { 10 | Component: PropTypes.func, 11 | pageProps: PropTypes.object 12 | } 13 | 14 | export default MyApp 15 | -------------------------------------------------------------------------------- /examples/helia-nestjs/src/main.ts: -------------------------------------------------------------------------------- 1 | import { NestFactory } from '@nestjs/core'; 2 | import { AppModule } from './app.module.js'; 3 | 4 | async function bootstrap() { 5 | const app = await NestFactory.create(AppModule); 6 | await app.listen(3000); 7 | } 8 | bootstrap().catch((err) => { 9 | console.error(err); // eslint-disable-line no-console 10 | process.exit(1); 11 | }); 12 | -------------------------------------------------------------------------------- /examples/helia-nextjs/styles/globals.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | padding: 0; 4 | margin: 0; 5 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, 6 | Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, sans-serif; 7 | } 8 | 9 | a { 10 | color: inherit; 11 | text-decoration: none; 12 | } 13 | 14 | * { 15 | box-sizing: border-box; 16 | } 17 | -------------------------------------------------------------------------------- /examples/helia-vue/vite.config.js: -------------------------------------------------------------------------------- 1 | import { fileURLToPath, URL } from 'node:url' 2 | import vue from '@vitejs/plugin-vue' 3 | import { defineConfig } from 'vite' 4 | 5 | // https://vitejs.dev/config/ 6 | export default defineConfig({ 7 | plugins: [vue()], 8 | resolve: { 9 | alias: { 10 | '@': fileURLToPath(new URL('./src', import.meta.url)) 11 | } 12 | } 13 | }) 14 | -------------------------------------------------------------------------------- /examples/helia-typescript/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ES2015", 4 | "target": "ES2015", 5 | 6 | "moduleResolution": "node", 7 | "skipLibCheck": true, 8 | "outDir": "./dist", 9 | 10 | // only necessary for the example linting check, your project may not need 11 | // these settings 12 | "strictNullChecks": true 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /examples/helia-jest/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-jest", 3 | "version": "1.0.0", 4 | "private": true, 5 | "type": "module", 6 | "description": "Test Helia with Jest", 7 | "scripts": { 8 | "test": "NODE_OPTIONS=--experimental-vm-modules jest" 9 | }, 10 | "dependencies": { 11 | "helia": "^2.0.3" 12 | }, 13 | "devDependencies": { 14 | "jest": "^29.6.2" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /examples/helia-vite/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | /test-results/ 26 | -------------------------------------------------------------------------------- /examples/helia-vite/src/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App' 4 | import './index.css' 5 | import { HeliaProvider } from '@/provider/HeliaProvider' 6 | 7 | ReactDOM.createRoot(document.getElementById('root')).render( 8 | 9 | 10 | 11 | 12 | 13 | ) 14 | -------------------------------------------------------------------------------- /examples/helia-create-car/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | dist 12 | dist-ssr 13 | *.local 14 | 15 | # Editor directories and files 16 | .vscode/* 17 | !.vscode/extensions.json 18 | .idea 19 | .DS_Store 20 | *.suo 21 | *.ntvs* 22 | *.njsproj 23 | *.sln 24 | *.sw? 25 | /test-results/ 26 | -------------------------------------------------------------------------------- /examples/helia-create-car/src/main.jsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom/client' 3 | import App from './App' 4 | import './index.css' 5 | import { HeliaProvider } from '@/provider/HeliaProvider' 6 | 7 | ReactDOM.createRoot(document.getElementById('root')).render( 8 | 9 | 10 | 11 | 12 | 13 | ) 14 | -------------------------------------------------------------------------------- /examples/helia-nestjs/test/jest-e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": ["js", "json", "ts"], 3 | "rootDir": ".", 4 | "testEnvironment": "node", 5 | "testRegex": ".e2e-spec.ts$", 6 | "transform": { 7 | "^.+\\.(t|j)s$": ["ts-jest", { 8 | "useESM": true 9 | }] 10 | }, 11 | "preset": "ts-jest/presets/default-esm", 12 | "moduleNameMapper": { 13 | "^(\\.{1,2}/.*)\\.[jt]s$": "$1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /examples/helia-jest-typescript/jest.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "moduleFileExtensions": [ 3 | "js", 4 | "json", 5 | "ts" 6 | ], 7 | "rootDir": "test", 8 | "testRegex": ".*\\.spec\\.ts$", 9 | "transform": { 10 | "^.+\\.(t|j)s$": ["ts-jest", { 11 | "useESM": true 12 | }] 13 | }, 14 | "preset": "ts-jest/presets/default-esm", 15 | "moduleNameMapper": { 16 | "^(\\.{1,2}/.*)\\.[jt]s$": "$1" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /examples/helia-vue/src/assets/main.css: -------------------------------------------------------------------------------- 1 | @import './base.css'; 2 | 3 | #app { 4 | max-width: 1280px; 5 | margin: 0 auto; 6 | padding: 2rem; 7 | 8 | font-weight: normal; 9 | } 10 | 11 | a, 12 | .green { 13 | text-decoration: none; 14 | color: hsla(160, 100%, 37%, 1); 15 | transition: 0.4s; 16 | } 17 | 18 | @media (hover: hover) { 19 | a:hover { 20 | background-color: hsla(160, 100%, 37%, 0.2); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /examples/helia-vite/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Helia + Vite + React 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/helia-vue/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Vite App 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/helia-create-car/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Helia Create Car Example 8 | 9 | 10 |
11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /examples/helia-electron/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Helia Electron 8 | 9 | 10 | 11 | 12 |

Helia in electron!

13 |

now check your console

14 | 15 | 16 | -------------------------------------------------------------------------------- /examples/helia-vue/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | pnpm-debug.log* 8 | lerna-debug.log* 9 | 10 | node_modules 11 | .DS_Store 12 | dist 13 | dist-ssr 14 | coverage 15 | *.local 16 | 17 | /cypress/videos/ 18 | /cypress/screenshots/ 19 | 20 | # Editor directories and files 21 | .vscode/* 22 | !.vscode/extensions.json 23 | .idea 24 | *.suo 25 | *.ntvs* 26 | *.njsproj 27 | *.sln 28 | *.sw? 29 | 30 | test-results/ 31 | playwright-report/ 32 | -------------------------------------------------------------------------------- /examples/helia-ts-node/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-ts-node", 3 | "version": "1.0.0", 4 | "private": true, 5 | "type": "module", 6 | "description": "Running Helia with ts-node", 7 | "scripts": { 8 | "start": "ts-node --esm ./src/index.ts", 9 | "test": "test-node-example test/*" 10 | }, 11 | "dependencies": { 12 | "helia": "^2.0.3" 13 | }, 14 | "devDependencies": { 15 | "ts-node": "^10.9.1", 16 | "test-ipfs-example": "^1.0.0", 17 | "typescript": "^5.1.6" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/helia-jest/test/index.spec.js: -------------------------------------------------------------------------------- 1 | /* eslint-env jest */ 2 | 3 | import { createHeliaNode } from '../src/index.js' 4 | 5 | describe('Helia', () => { 6 | let helia 7 | 8 | beforeEach(async () => { 9 | helia = await createHeliaNode() 10 | }) 11 | 12 | afterEach(async () => { 13 | if (helia != null) { 14 | await helia.stop() 15 | } 16 | }) 17 | 18 | describe('libp2p', () => { 19 | it('should have a peer id', async () => { 20 | expect(helia.libp2p.peerId).toBeTruthy() 21 | }) 22 | }) 23 | }) 24 | -------------------------------------------------------------------------------- /examples/helia-cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-cjs", 3 | "version": "1.0.0", 4 | "private": true, 5 | "type": "commonjs", 6 | "description": "Using Helia from CommonJS", 7 | "license": "MIT", 8 | "main": "index.js", 9 | "scripts": { 10 | "start": "node index.js", 11 | "serve": "npm run start", 12 | "test": "test-node-example test/*" 13 | }, 14 | "dependencies": { 15 | "@helia/unixfs": "^1.4.1", 16 | "helia": "^2.0.3" 17 | }, 18 | "devDependencies": { 19 | "test-ipfs-example": "^1.0.0" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/helia-jest-typescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-jest-typescript", 3 | "version": "1.0.0", 4 | "private": true, 5 | "type": "module", 6 | "description": "Test Helia with Jest and TypeScript", 7 | "scripts": { 8 | "test": "NODE_OPTIONS=--experimental-vm-modules jest" 9 | }, 10 | "dependencies": { 11 | "@helia/interface": "^2.0.0", 12 | "helia": "^2.0.3" 13 | }, 14 | "devDependencies": { 15 | "@types/jest": "^29.5.2", 16 | "jest": "^29.6.2", 17 | "ts-jest": "^29.1.1", 18 | "typescript": "^5.1.6" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/helia-typescript/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-typescript", 3 | "version": "1.0.0", 4 | "private": true, 5 | "type": "module", 6 | "description": "Building Helia with TypeScript", 7 | "license": "MIT", 8 | "main": "index.js", 9 | "scripts": { 10 | "build": "tsc", 11 | "start": "node dist/src/index.js", 12 | "test": "npm run build && test-node-example test/*" 13 | }, 14 | "dependencies": { 15 | "helia": "^2.0.3" 16 | }, 17 | "devDependencies": { 18 | "test-ipfs-example": "^1.0.0", 19 | "typescript": "^5.1.6" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /examples/helia-nestjs/src/app.controller.ts: -------------------------------------------------------------------------------- 1 | import { Controller, Get } from '@nestjs/common'; 2 | import { AppService } from './app.service.js'; 3 | 4 | @Controller() 5 | export class AppController { 6 | constructor(private readonly appService: AppService) {} 7 | 8 | @Get() 9 | async getHeliaVersion(): Promise { 10 | const helia = await this.appService.getHelia(); 11 | return 'Helia is running, PeerId ' + helia.libp2p.peerId.toString(); 12 | } 13 | 14 | async onApplicationShutdown(): Promise { 15 | await this.appService.onApplicationShutdown(); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /examples/helia-101/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import { fileURLToPath } from 'url' 3 | import { waitForOutput } from 'test-ipfs-example/node' 4 | 5 | const __dirname = path.dirname(fileURLToPath(import.meta.url)) 6 | 7 | await waitForOutput('Added file contents: Hello World 101', 'node', [path.resolve(__dirname, '../101-basics.js')]) 8 | 9 | await waitForOutput('Added file contents: Hello World 201', 'node', [path.resolve(__dirname, '../201-storage.js')]) 10 | 11 | await waitForOutput('Fetched file contents: Hello World 301', 'node', [path.resolve(__dirname, '../301-networking.js')]) 12 | -------------------------------------------------------------------------------- /examples/helia-nestjs/src/app.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@nestjs/common'; 2 | import type { Helia } from '@helia/interface'; 3 | 4 | @Injectable() 5 | export class AppService { 6 | private helia?: Helia; 7 | 8 | async getHelia(): Promise { 9 | if (this.helia == null) { 10 | const { createHelia } = await import('helia'); 11 | this.helia = await createHelia(); 12 | } 13 | 14 | return this.helia; 15 | } 16 | 17 | async onApplicationShutdown(): Promise { 18 | if (this.helia != null) { 19 | await this.helia.stop(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/helia-jest-typescript/test/index.spec.ts: -------------------------------------------------------------------------------- 1 | /* eslint-env jest */ 2 | 3 | import { createHeliaNode } from '../src/index.js' 4 | import type { Helia } from '@helia/interface' 5 | 6 | describe('Helia', () => { 7 | let helia: Helia 8 | 9 | beforeEach(async () => { 10 | helia = await createHeliaNode() 11 | }) 12 | 13 | afterEach(async () => { 14 | if (helia != null) { 15 | await helia.stop() 16 | } 17 | }) 18 | 19 | describe('libp2p', () => { 20 | it('should have a peer id', async () => { 21 | expect(helia.libp2p.peerId).toBeTruthy() 22 | }) 23 | }) 24 | }) 25 | -------------------------------------------------------------------------------- /examples/helia-101/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-cjs/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-jest/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-nestjs/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-nextjs/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-parcel/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-vite/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-vue/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-create-car/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-electron/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-esbuild/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-script-tag/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-ts-node/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-typescript/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-webpack/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-jest-typescript/.github/workflows/sync.yml: -------------------------------------------------------------------------------- 1 | name: pull 2 | 3 | on: 4 | workflow_dispatch 5 | 6 | jobs: 7 | sync: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - uses: actions/checkout@v2 11 | - name: Pull from another repository 12 | uses: ipfs-examples/actions-pull-directory-from-repo@main 13 | with: 14 | source-repo: ipfs-examples/helia-examples 15 | source-folder-path: examples/${{ github.event.repository.name }} 16 | source-branch: main 17 | target-branch: main 18 | git-username: github-actions 19 | git-email: github-actions@github.com 20 | -------------------------------------------------------------------------------- /examples/helia-nextjs/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import { setup, expect } from 'test-ipfs-example/browser' 2 | 3 | // Setup 4 | const test = setup() 5 | 6 | test.describe('integrate ipfs with nextjs:', () => { 7 | // DOM 8 | const id = '[data-test=id]' 9 | const status = '[data-test=status]' 10 | 11 | test.beforeEach(async ({ servers, page }) => { 12 | await page.goto(servers[0].url) 13 | }) 14 | 15 | test('should properly initialized a IPFS node and print some properties', async ({ page }) => { 16 | await page.waitForSelector(id) 17 | 18 | expect(await page.isVisible(id)).toBeTruthy() 19 | expect(await page.textContent(status)).toContain('Online') 20 | }) 21 | }) 22 | -------------------------------------------------------------------------------- /examples/helia-nestjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "ES2020", 4 | "declaration": true, 5 | "removeComments": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "allowSyntheticDefaultImports": true, 9 | "target": "ES2020", 10 | "sourceMap": true, 11 | "outDir": "./dist", 12 | "baseUrl": "./", 13 | "incremental": true, 14 | "skipLibCheck": true, 15 | "strictNullChecks": true, 16 | "noImplicitAny": false, 17 | "strictBindCallApply": false, 18 | "forceConsistentCasingInFileNames": false, 19 | "noFallthroughCasesInSwitch": false, 20 | "moduleResolution": "Node" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /examples/helia-vue/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-vue", 3 | "version": "0.0.0", 4 | "description": "Using Helia with vue", 5 | "private": true, 6 | "type": "module", 7 | "scripts": { 8 | "clean": "rimraf ./dist", 9 | "dev": "vite", 10 | "start": "vite", 11 | "build": "vite build", 12 | "preview": "vite preview", 13 | "test": "npm run build && test-browser-example test" 14 | }, 15 | "dependencies": { 16 | "@helia/unixfs": "^1.4.1", 17 | "helia": "^2.0.3", 18 | "it-all": "^3.0.1", 19 | "vue": "^3.2.47" 20 | }, 21 | "devDependencies": { 22 | "@vitejs/plugin-vue": "^4.0.0", 23 | "rimraf": "^5.0.0", 24 | "test-ipfs-example": "^1.0.0", 25 | "vite": "^4.1.4" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /examples/helia-webpack/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /examples/helia-nestjs/.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: '@typescript-eslint/parser', 3 | parserOptions: { 4 | project: 'tsconfig.json', 5 | tsconfigRootDir: __dirname, 6 | sourceType: 'module', 7 | }, 8 | plugins: ['@typescript-eslint/eslint-plugin'], 9 | extends: [ 10 | 'plugin:@typescript-eslint/recommended', 11 | 'plugin:prettier/recommended', 12 | ], 13 | root: true, 14 | env: { 15 | node: true, 16 | jest: true, 17 | }, 18 | ignorePatterns: ['.eslintrc.js'], 19 | rules: { 20 | '@typescript-eslint/interface-name-prefix': 'off', 21 | '@typescript-eslint/explicit-function-return-type': 'off', 22 | '@typescript-eslint/explicit-module-boundary-types': 'off', 23 | '@typescript-eslint/no-explicit-any': 'off', 24 | }, 25 | }; 26 | -------------------------------------------------------------------------------- /examples/helia-101/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-101", 3 | "version": "1.0.0", 4 | "private": true, 5 | "type": "module", 6 | "description": "Getting started with Helia", 7 | "license": "MIT", 8 | "main": "index.js", 9 | "scripts": { 10 | "start": "node index.js", 11 | "serve": "npm run start", 12 | "test": "test-node-example test/*" 13 | }, 14 | "dependencies": { 15 | "@chainsafe/libp2p-noise": "^13.0.1", 16 | "@chainsafe/libp2p-yamux": "^5.0.0", 17 | "@helia/unixfs": "^1.4.1", 18 | "@libp2p/bootstrap": "^9.0.8", 19 | "@libp2p/tcp": "^8.0.9", 20 | "blockstore-core": "^4.1.0", 21 | "datastore-core": "^9.1.1", 22 | "helia": "^2.0.3", 23 | "libp2p": "^0.46.14" 24 | }, 25 | "devDependencies": { 26 | "test-ipfs-example": "^1.0.0" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /examples/helia-vite/src/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | padding: 2rem; 5 | text-align: center; 6 | } 7 | 8 | .logo { 9 | height: 6em; 10 | padding: 1.5em; 11 | will-change: filter; 12 | transition: filter 300ms; 13 | } 14 | .logo:hover { 15 | filter: drop-shadow(0 0 2em #646cffaa); 16 | } 17 | .logo.react:hover { 18 | filter: drop-shadow(0 0 2em #61dafbaa); 19 | } 20 | 21 | @keyframes logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } 29 | 30 | @media (prefers-reduced-motion: no-preference) { 31 | a:nth-of-type(2) .logo { 32 | animation: logo-spin infinite 20s linear; 33 | } 34 | } 35 | 36 | .card { 37 | padding: 2em; 38 | } 39 | 40 | .read-the-docs { 41 | color: #888; 42 | } 43 | -------------------------------------------------------------------------------- /examples/helia-electron/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-in-electron", 3 | "version": "1.0.0", 4 | "private": true, 5 | "description": "A minimal Electron application with Helia", 6 | "keywords": [ 7 | "Electron", 8 | "IPFS", 9 | "Example" 10 | ], 11 | "main": "main.js", 12 | "scripts": { 13 | "clean": "echo 'Nothing to clean...'", 14 | "start": "electron .", 15 | "serve": "npm run start", 16 | "test": "xvfb-maybe test-node-example test/*" 17 | }, 18 | "dependencies": { 19 | "helia": "^2.0.3" 20 | }, 21 | "devDependencies": { 22 | "electron": "^27.0.0", 23 | "electron-rebuild": "^3.1.1", 24 | "test-ipfs-example": "^1.0.0", 25 | "xvfb-maybe": "^0.2.1" 26 | }, 27 | "greenkeeper": { 28 | "ignore": [ 29 | "electron" 30 | ] 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /examples/helia-webpack/src/app.css: -------------------------------------------------------------------------------- 1 | ::placeholder { 2 | color: rgb(0 0 0 / 30%); 3 | } 4 | 5 | form { 6 | margin: 1.25rem 0; 7 | } 8 | 9 | .window { 10 | display: flex; 11 | flex-direction: column; 12 | background: #222; 13 | color: #fff; 14 | height: 400px; 15 | } 16 | 17 | .window .header { 18 | flex-basis: 3rem; 19 | background: #c6c6c6; 20 | position: relative; 21 | } 22 | 23 | .window .header:after { 24 | content: ". . ."; 25 | position: absolute; 26 | left: 12px; 27 | right: 0; 28 | top: -3px; 29 | font-family: "Times New Roman", Times, serif; 30 | font-size: 96px; 31 | color: #fff; 32 | line-height: 0; 33 | letter-spacing: -12px; 34 | } 35 | 36 | .terminal { 37 | margin: 20px; 38 | font-family: monospace; 39 | font-size: 16px; 40 | overflow: auto; 41 | flex: 1; 42 | } 43 | -------------------------------------------------------------------------------- /examples/helia-create-car/src/App.css: -------------------------------------------------------------------------------- 1 | #root { 2 | max-width: 1280px; 3 | margin: 0 auto; 4 | padding: 2rem; 5 | text-align: center; 6 | } 7 | 8 | .logo { 9 | height: 6em; 10 | padding: 1.5em; 11 | will-change: filter; 12 | transition: filter 300ms; 13 | } 14 | .logo:hover { 15 | filter: drop-shadow(0 0 2em #646cffaa); 16 | } 17 | .logo.react:hover { 18 | filter: drop-shadow(0 0 2em #61dafbaa); 19 | } 20 | 21 | @keyframes logo-spin { 22 | from { 23 | transform: rotate(0deg); 24 | } 25 | to { 26 | transform: rotate(360deg); 27 | } 28 | } 29 | 30 | @media (prefers-reduced-motion: no-preference) { 31 | a:nth-of-type(2) .logo { 32 | animation: logo-spin infinite 20s linear; 33 | } 34 | } 35 | 36 | .card { 37 | padding: 2em; 38 | } 39 | 40 | .read-the-docs { 41 | color: #888; 42 | } 43 | -------------------------------------------------------------------------------- /examples/helia-vue/src/plugins/HeliaProviderPlugin.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { unixfs } from '@helia/unixfs' 4 | import { createHelia } from 'helia' 5 | import { ref } from 'vue' 6 | 7 | export const HeliaProviderPlugin = { 8 | install: async (app) => { 9 | const loading = ref(true) 10 | const error = ref('') 11 | const helia = ref() 12 | const fs = ref() 13 | app.provide('HeliaProvider', { 14 | loading, 15 | error, 16 | helia, 17 | fs 18 | }) 19 | try { 20 | const instance = await createHelia() 21 | loading.value = false 22 | helia.value = instance 23 | fs.value = unixfs(instance) 24 | } catch (e) { 25 | console.error(e) 26 | error.value = e.toString() 27 | loading.value = false 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/helia-script-tag/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-script-tag", 3 | "version": "1.0.0", 4 | "private": true, 5 | "type": "module", 6 | "description": "Using Helia in the browser via a script tag", 7 | "keywords": [], 8 | "license": "MIT", 9 | "scripts": { 10 | "clean": "rimraf ./dist ./.cache ./node_modules/.vite", 11 | "build": "vite build", 12 | "serve": "vite dev --port 8888", 13 | "start": "npm run serve", 14 | "test": "npm run build && test-browser-example test" 15 | }, 16 | "browserslist": "last 1 Chrome version", 17 | "devDependencies": { 18 | "@babel/core": "^7.14.8", 19 | "@playwright/test": "^1.12.3", 20 | "playwright": "^1.12.3", 21 | "process": "^0.11.10", 22 | "rimraf": "^5.0.0", 23 | "test-ipfs-example": "^1.0.0", 24 | "vite": "^4.2.1" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /examples/helia-create-car/src/provider/FileProvider.jsx: -------------------------------------------------------------------------------- 1 | import PropTypes from 'prop-types' 2 | import React, { createContext, useState } from 'react' 3 | 4 | export const FileContext = createContext({ 5 | files: /** @type {File[]} */([]), 6 | setFiles: /** @type {(files: File[]) => void} */() => {} 7 | }) 8 | 9 | /** 10 | * @param {object} param0 11 | * @param {React.ReactNode} param0.children 12 | * @returns 13 | */ 14 | export default function FileProvider ({ children }) { 15 | const [files, setFiles] = useState(/** @type {File[]} */([])) 16 | const providerValue = { 17 | files, 18 | setFiles 19 | } 20 | return ( 21 | 22 | {children} 23 | 24 | ) 25 | } 26 | 27 | FileProvider.propTypes = { 28 | children: PropTypes.node.isRequired 29 | } 30 | -------------------------------------------------------------------------------- /examples/helia-nestjs/test/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { type INestApplication } from '@nestjs/common'; 2 | import { Test, type TestingModule } from '@nestjs/testing'; 3 | import request from 'supertest'; 4 | import { AppModule } from '../src/app.module.js'; 5 | 6 | describe('AppController (e2e)', () => { 7 | let app: INestApplication; 8 | 9 | beforeEach(async () => { 10 | const moduleFixture: TestingModule = await Test.createTestingModule({ 11 | imports: [AppModule], 12 | }).compile(); 13 | 14 | app = moduleFixture.createNestApplication(); 15 | await app.init(); 16 | }); 17 | 18 | afterEach(async () => { 19 | await app.close(); 20 | }); 21 | 22 | it('/ (GET)', async () => { 23 | return request(app.getHttpServer()) 24 | .get('/') 25 | .expect(200) 26 | .expect(/Helia is running/); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /examples/helia-nestjs/src/app.controller.spec.ts: -------------------------------------------------------------------------------- 1 | import { Test, type TestingModule } from '@nestjs/testing'; 2 | import { AppController } from './app.controller.js'; 3 | import { AppService } from './app.service.js'; 4 | 5 | describe('AppController', () => { 6 | let appController: AppController; 7 | 8 | beforeEach(async () => { 9 | const app: TestingModule = await Test.createTestingModule({ 10 | controllers: [AppController], 11 | providers: [AppService], 12 | }).compile(); 13 | 14 | appController = app.get(AppController); 15 | }); 16 | 17 | describe('root', () => { 18 | it('should return "Helia is running"', async () => { 19 | expect(await appController.getHeliaVersion()).toContain( 20 | 'Helia is running', 21 | ); 22 | 23 | await appController.onApplicationShutdown(); 24 | }); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /examples/helia-vite/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-vite", 3 | "version": "0.0.0", 4 | "description": "Using Helia with vite", 5 | "private": true, 6 | "type": "module", 7 | "scripts": { 8 | "clean": "rimraf ./dist", 9 | "dev": "vite", 10 | "start": "vite", 11 | "build": "vite build", 12 | "preview": "vite preview", 13 | "test": "npm run build && test-browser-example test" 14 | }, 15 | "dependencies": { 16 | "@helia/unixfs": "^1.4.1", 17 | "helia": "^2.0.3", 18 | "prop-types": "^15.8.1", 19 | "react": "^18.2.0", 20 | "react-dom": "^18.2.0", 21 | "rimraf": "^5.0.0" 22 | }, 23 | "devDependencies": { 24 | "@playwright/test": "^1.31.2", 25 | "@types/react": "^18.0.28", 26 | "@types/react-dom": "^18.0.11", 27 | "@vitejs/plugin-react": "^4.0.0", 28 | "test-ipfs-example": "^1.0.0", 29 | "vite": "^4.2.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/helia-nextjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-nextjs", 3 | "version": "1.0.0", 4 | "description": "Using Helia with nextjs", 5 | "private": true, 6 | "type": "module", 7 | "scripts": { 8 | "clean": "rimraf ./dist ./.next", 9 | "dev": "next dev", 10 | "build": "next build && next export -o dist", 11 | "serve": "npm run dev", 12 | "start": "next start", 13 | "lint": "next lint", 14 | "test": "npm run build && test-browser-example test" 15 | }, 16 | "dependencies": { 17 | "helia": "^2.0.3", 18 | "next": "^13.2.4", 19 | "react": "^18.2.0", 20 | "react-dom": "^18.2.0" 21 | }, 22 | "devDependencies": { 23 | "@playwright/test": "^1.32.1", 24 | "eslint": "^8.36.0", 25 | "eslint-config-next": "^13.2.4", 26 | "interface-datastore": "^8.2.0", 27 | "playwright": "^1.32.1", 28 | "rimraf": "^5.0.0", 29 | "test-ipfs-example": "^1.0.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/helia-esbuild/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-esbuild", 3 | "version": "1.0.0", 4 | "private": true, 5 | "type": "module", 6 | "description": "Bundle Helia with esbuild", 7 | "keywords": [], 8 | "license": "ISC", 9 | "author": "", 10 | "scripts": { 11 | "clean": "rimraf ./dist", 12 | "build": "mkdir -p dist && cp src/index.html src/style.css dist && node esbuild.js", 13 | "start": "npm run build && esbuild --servedir=dist", 14 | "test": "npm run build && test-browser-example test" 15 | }, 16 | "browserslist": "last 1 Chrome version", 17 | "dependencies": { 18 | "@helia/unixfs": "^1.4.1", 19 | "helia": "^2.0.3" 20 | }, 21 | "devDependencies": { 22 | "@babel/core": "^7.14.8", 23 | "@playwright/test": "^1.12.3", 24 | "esbuild": "^0.19.4", 25 | "playwright": "^1.12.3", 26 | "process": "^0.11.10", 27 | "rimraf": "^5.0.0", 28 | "test-ipfs-example": "^1.0.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/helia-script-tag/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import { setup } from 'test-ipfs-example/browser' 2 | 3 | // Setup 4 | const test = setup() 5 | 6 | test.describe('using script tag:', () => { 7 | // DOM 8 | const status = '#statusValue' 9 | const node = '#nodeId' 10 | const stopHelia = '.e2e-stopHelia' 11 | 12 | test.beforeEach(async ({ servers, page }) => { 13 | await page.goto(servers[0].url) 14 | }) 15 | 16 | test('should properly initialized a IPFS node and print the status', async ({ page }) => { 17 | // wait for page to init 18 | await page.waitForSelector(`${status}:has-text("Not Started")`) 19 | 20 | // wait for helia to start 21 | await page.waitForSelector(`${status}:has-text("Online")`) 22 | await page.waitForSelector(`${node}:has-text("12D3")`) 23 | 24 | // wait for helia to stop 25 | await page.click(stopHelia) 26 | await page.waitForSelector(`${status}:has-text("Offline")`) 27 | }) 28 | }) 29 | -------------------------------------------------------------------------------- /examples/helia-vue/src/components/TextCommiter.vue: -------------------------------------------------------------------------------- 1 | 13 | 14 | 27 | 28 | -------------------------------------------------------------------------------- /examples/helia-create-car/src/App.jsx: -------------------------------------------------------------------------------- 1 | import { React } from 'react' 2 | import './App.css' 3 | import CarCreator from '@/components/CarCreator' 4 | import FileUploader from '@/components/FileUploader' 5 | import { useHelia } from '@/hooks/useHelia' 6 | import FileProvider from '@/provider/FileProvider' 7 | 8 | function App () { 9 | const { error, starting } = useHelia() 10 | 11 | let statusColor = 'green' 12 | if (error) { 13 | statusColor = 'red' 14 | } else if (starting) { 15 | statusColor = 'yellow' 16 | } 17 | 18 | return ( 19 |
20 |
Helia Status
28 |
29 | 30 | 31 | 32 | 33 |
34 | ) 35 | } 36 | 37 | export default App 38 | -------------------------------------------------------------------------------- /examples/helia-create-car/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-create-car", 3 | "version": "0.0.0", 4 | "description": "Using Helia with vite - upload files and get a car file back", 5 | "private": true, 6 | "type": "module", 7 | "scripts": { 8 | "clean": "rimraf ./dist", 9 | "dev": "vite", 10 | "start": "vite", 11 | "build": "vite build", 12 | "preview": "vite preview", 13 | "test": "npm run build && test-browser-example test" 14 | }, 15 | "dependencies": { 16 | "@helia/car": "^1.0.0", 17 | "@helia/unixfs": "^1.4.1", 18 | "@ipld/car": "^5.1.1", 19 | "helia": "^2.0.3", 20 | "prop-types": "^15.8.1", 21 | "react": "^18.2.0", 22 | "react-dom": "^18.2.0", 23 | "rimraf": "^5.0.0" 24 | }, 25 | "devDependencies": { 26 | "@playwright/test": "^1.31.2", 27 | "@types/react": "^18.0.28", 28 | "@types/react-dom": "^18.0.11", 29 | "@vitejs/plugin-react": "^4.0.0", 30 | "test-ipfs-example": "^1.0.0", 31 | "vite": "^4.2.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /examples/helia-101/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-cjs/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-jest/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-vite/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-vue/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-create-car/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-electron/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-esbuild/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-nestjs/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-nextjs/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-parcel/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-ts-node/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-typescript/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-webpack/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-jest-typescript/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [IPFS Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-script-tag/.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | # ⚠️ IMPORTANT ⚠️ 2 | 3 | # Please do not create a Pull Request for this repository 4 | 5 | The contents of this repository are automatically synced from the parent [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) so any changes made to the standalone repository will be lost after the next sync. 6 | 7 | Please open a PR against [Helia Examples](https://github.com/ipfs-examples/helia-examples) instead. 8 | 9 | ## Contributing 10 | 11 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 12 | 13 | 1. Fork the [Helia Examples Project](https://github.com/ipfs-examples/helia-examples) 14 | 2. Create your Feature Branch (`git checkout -b feature/amazing-example`) 15 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing example'`) 16 | 4. Push to the Branch (`git push origin feature/amazing-example`) 17 | 5. Open a Pull Request 18 | -------------------------------------------------------------------------------- /examples/helia-parcel/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-parcel", 3 | "version": "1.0.0", 4 | "private": true, 5 | "type": "module", 6 | "description": "Bundle Helia with parcel", 7 | "keywords": [], 8 | "license": "ISC", 9 | "author": "", 10 | "scripts": { 11 | "clean": "rimraf ./dist ./.cache ./.parcel-cache", 12 | "build": "parcel build src/index.html", 13 | "serve": "parcel serve src/index.html --open -p 8888", 14 | "start": "npm run serve", 15 | "test": "npm run build && playwright test test" 16 | }, 17 | "browserslist": "last 1 Chrome version", 18 | "dependencies": { 19 | "@helia/unixfs": "^1.4.1", 20 | "helia": "^2.0.3" 21 | }, 22 | "devDependencies": { 23 | "@babel/core": "^7.14.8", 24 | "@playwright/test": "^1.12.3", 25 | "parcel": "^2.9.1", 26 | "playwright": "^1.12.3", 27 | "process": "^0.11.10", 28 | "rimraf": "^5.0.0", 29 | "test-ipfs-example": "^1.0.0" 30 | }, 31 | "@parcel/resolver-default": { 32 | "packageExports": true 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /examples/helia-esbuild/src/style.css: -------------------------------------------------------------------------------- 1 | ::placeholder { 2 | color: rgb(0 0 0 / 30%); 3 | } 4 | 5 | form { 6 | margin: 1.25rem 0; 7 | } 8 | 9 | .window { 10 | display: flex; 11 | flex-direction: column; 12 | background: #222; 13 | color: #fff; 14 | height: 400px; 15 | } 16 | 17 | .window .header { 18 | flex-basis: 3rem; 19 | background: #c6c6c6; 20 | position: relative; 21 | } 22 | 23 | .window .header:after { 24 | content: ". . ."; 25 | position: absolute; 26 | left: 12px; 27 | right: 0; 28 | top: -3px; 29 | font-family: "Times New Roman", Times, serif; 30 | font-size: 96px; 31 | color: #fff; 32 | line-height: 0; 33 | letter-spacing: -12px; 34 | } 35 | 36 | .terminal { 37 | margin: 20px; 38 | font-family: monospace; 39 | font-size: 16px; 40 | overflow: auto; 41 | flex: 1; 42 | } 43 | 44 | .terminal a, .terminal a:active, .terminal a:visited { 45 | color: #0cb892 46 | } 47 | 48 | .terminal a:hover { 49 | color: #fff 50 | } 51 | 52 | .terminal p { 53 | margin: 0; 54 | margin-bottom: 0.5em; 55 | } 56 | -------------------------------------------------------------------------------- /examples/helia-parcel/src/style.css: -------------------------------------------------------------------------------- 1 | ::placeholder { 2 | color: rgb(0 0 0 / 30%); 3 | } 4 | 5 | form { 6 | margin: 1.25rem 0; 7 | } 8 | 9 | .window { 10 | display: flex; 11 | flex-direction: column; 12 | background: #222; 13 | color: #fff; 14 | height: 400px; 15 | } 16 | 17 | .window .header { 18 | flex-basis: 3rem; 19 | background: #c6c6c6; 20 | position: relative; 21 | } 22 | 23 | .window .header:after { 24 | content: ". . ."; 25 | position: absolute; 26 | left: 12px; 27 | right: 0; 28 | top: -3px; 29 | font-family: "Times New Roman", Times, serif; 30 | font-size: 96px; 31 | color: #fff; 32 | line-height: 0; 33 | letter-spacing: -12px; 34 | } 35 | 36 | .terminal { 37 | margin: 20px; 38 | font-family: monospace; 39 | font-size: 16px; 40 | overflow: auto; 41 | flex: 1; 42 | } 43 | 44 | .terminal a, .terminal a:active, .terminal a:visited { 45 | color: #0cb892 46 | } 47 | 48 | .terminal a:hover { 49 | color: #fff 50 | } 51 | 52 | .terminal p { 53 | margin: 0; 54 | margin-bottom: 0.5em; 55 | } 56 | -------------------------------------------------------------------------------- /examples/helia-nextjs/components/ipfs.js: -------------------------------------------------------------------------------- 1 | import { createHelia } from 'helia' 2 | import { React, useState, useEffect } from 'react' 3 | 4 | const IpfsComponent = () => { 5 | const [id, setId] = useState(null) 6 | const [helia, setHelia] = useState(null) 7 | const [isOnline, setIsOnline] = useState(false) 8 | 9 | useEffect(() => { 10 | const init = async () => { 11 | if (helia) return 12 | 13 | const heliaNode = await createHelia() 14 | 15 | const nodeId = heliaNode.libp2p.peerId.toString() 16 | const nodeIsOnline = heliaNode.libp2p.isStarted() 17 | 18 | setHelia(heliaNode) 19 | setId(nodeId) 20 | setIsOnline(nodeIsOnline) 21 | } 22 | 23 | init() 24 | }, [helia]) 25 | 26 | if (!helia || !id) { 27 | return

Connecting to IPFS...

28 | } 29 | 30 | return ( 31 |
32 |

ID: {id.toString()}

33 |

Status: {isOnline ? 'Online' : 'Offline'}

34 |
35 | ) 36 | } 37 | 38 | export default IpfsComponent 39 | -------------------------------------------------------------------------------- /examples/helia-nextjs/public/vercel.svg: -------------------------------------------------------------------------------- 1 | 3 | 4 | -------------------------------------------------------------------------------- /examples/helia-create-car/src/components/FileUploader.jsx: -------------------------------------------------------------------------------- 1 | import React, { useCallback } from 'react' 2 | import { useFiles } from '@/hooks/useFiles' 3 | 4 | /** 5 | * @returns {React.FunctionComponent} 6 | */ 7 | export default function FileUploader () { 8 | const { files, setFiles } = useFiles() 9 | const handleFileEvent = useCallback((e) => { 10 | const filesToUpload = Array.prototype.slice.call(e.target.files) 11 | 12 | setFiles(filesToUpload) 13 | }, [files]) 14 | 15 | return ( 16 | <> 17 | 22 | 23 |
24 | {files.map((file, idx) => ( 25 |
26 | {file.name} 27 |
28 | ))} 29 |
30 | 31 | ) 32 | } 33 | -------------------------------------------------------------------------------- /examples/helia-101/101-basics.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { unixfs } from '@helia/unixfs' 4 | import { createHelia } from 'helia' 5 | 6 | // create a Helia node 7 | const helia = await createHelia() 8 | 9 | // create a filesystem on top of Helia, in this case it's UnixFS 10 | const fs = unixfs(helia) 11 | 12 | // we will use this TextEncoder to turn strings into Uint8Arrays 13 | const encoder = new TextEncoder() 14 | 15 | // add the bytes to your node and receive a unique content identifier 16 | const cid = await fs.addBytes(encoder.encode('Hello World 101'), { 17 | onProgress: (evt) => { 18 | console.info('add event', evt.type, evt.detail) 19 | } 20 | }) 21 | 22 | console.log('Added file:', cid.toString()) 23 | 24 | // this decoder will turn Uint8Arrays into strings 25 | const decoder = new TextDecoder() 26 | let text = '' 27 | 28 | for await (const chunk of fs.cat(cid, { 29 | onProgress: (evt) => { 30 | console.info('cat event', evt.type, evt.detail) 31 | } 32 | })) { 33 | text += decoder.decode(chunk, { 34 | stream: true 35 | }) 36 | } 37 | 38 | console.log('Added file contents:', text) 39 | -------------------------------------------------------------------------------- /examples/helia-script-tag/vite.config.js: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'vite' 2 | 3 | export default defineConfig({ 4 | build: { 5 | target: 'es2020', 6 | minify: false, 7 | // disable @rollup/plugin-commonjs https://github.com/vitejs/vite/issues/9703#issuecomment-1216662109 8 | // should be removable with vite 4 https://vitejs.dev/blog/announcing-vite3.html#esbuild-deps-optimization-at-build-time-experimental 9 | commonjsOptions: { 10 | include: [] 11 | } 12 | }, 13 | define: { 14 | 'process.env.NODE_DEBUG': 'false', 15 | global: 'globalThis' 16 | }, 17 | optimizeDeps: { 18 | // enable esbuild dep optimization during build https://github.com/vitejs/vite/issues/9703#issuecomment-1216662109 19 | // should be removable with vite 4 https://vitejs.dev/blog/announcing-vite3.html#esbuild-deps-optimization-at-build-time-experimental 20 | disabled: false, 21 | 22 | // target: es2020 added as workaround to make big ints work 23 | // - should be removable with vite 4 24 | // https://github.com/vitejs/vite/issues/9062#issuecomment-1182818044 25 | esbuildOptions: { 26 | target: 'es2020' 27 | } 28 | } 29 | }) 30 | -------------------------------------------------------------------------------- /examples/helia-cjs/index.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | // this file is regular CommonJS 4 | 5 | async function main () { 6 | const { createHelia } = await import('helia') 7 | const { unixfs } = await import('@helia/unixfs') 8 | 9 | // create a Helia node 10 | const helia = await createHelia() 11 | 12 | // print out our node's PeerId 13 | console.log(helia.libp2p.peerId) 14 | 15 | // create a filesystem on top of Helia, in this case it's UnixFS 16 | const fs = unixfs(helia) 17 | 18 | // we will use this TextEncoder to turn strings into Uint8Arrays 19 | const encoder = new TextEncoder() 20 | 21 | // add the bytes to your node and receive a unique content identifier 22 | const cid = await fs.addBytes(encoder.encode('Hello World 101'), helia.blockstore) 23 | 24 | console.log('Added file:', cid.toString()) 25 | 26 | // this decoder will turn Uint8Arrays into strings 27 | const decoder = new TextDecoder() 28 | let text = '' 29 | 30 | for await (const chunk of fs.cat(cid)) { 31 | text += decoder.decode(chunk, { 32 | stream: true 33 | }) 34 | } 35 | 36 | console.log('Added file contents:', text) 37 | } 38 | 39 | main().catch(err => { 40 | console.error(err) 41 | process.exit(1) 42 | }) 43 | -------------------------------------------------------------------------------- /examples/helia-webpack/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import { setup, expect } from 'test-ipfs-example/browser' 2 | 3 | // Setup 4 | const test = setup() 5 | 6 | test.describe('bundle Helia with Webpack:', () => { 7 | // DOM 8 | const nameInput = '#file-name' 9 | const contentInput = '#file-content' 10 | const submitBtn = '#add-submit' 11 | const output = '#output' 12 | 13 | test.beforeEach(async ({ servers, page }) => { 14 | await page.goto(servers[0].url) 15 | }) 16 | 17 | test('should properly initialized a Helia node and add/get a file', async ({ page }) => { 18 | const fileName = 'test.txt' 19 | const stringToUse = 'Hello world!' 20 | 21 | await page.fill(nameInput, fileName) 22 | await page.fill(contentInput, stringToUse) 23 | await page.click(submitBtn) 24 | 25 | await page.waitForSelector(`${output}:has-text("/bafkreigaknpexyvxt76zgkitavbwx6ejgfheup5oybpm77f3pxzrvwpfdi")`) 26 | 27 | const outputContent = await page.textContent(output) 28 | 29 | expect(outputContent).toContain('bafkreigaknpexyvxt76zgkitavbwx6ejgfheup5oybpm77f3pxzrvwpfdi') 30 | expect(outputContent).toContain('https://ipfs.io/ipfs/bafkreigaknpexyvxt76zgkitavbwx6ejgfheup5oybpm77f3pxzrvwpfdi') 31 | expect(outputContent).toContain(fileName) 32 | expect(outputContent).toContain(stringToUse) 33 | }) 34 | }) 35 | -------------------------------------------------------------------------------- /examples/helia-esbuild/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import { setup, expect } from 'test-ipfs-example/browser' 2 | 3 | // Setup 4 | const test = setup() 5 | 6 | test.describe('bundle ipfs with esbuild:', () => { 7 | // DOM 8 | const nameInput = '#file-name' 9 | const contentInput = '#file-content' 10 | const submitBtn = '#add-submit' 11 | const output = '#output' 12 | 13 | test.beforeEach(async ({ servers, page }) => { 14 | await page.goto(servers[0].url) 15 | }) 16 | 17 | test('should initialize a Helia node and add/get a file', async ({ page }) => { 18 | const outputLocator = page.locator(output) 19 | await expect(outputLocator).toHaveText(/Helia node ready/) 20 | 21 | const fileName = 'test.txt' 22 | const fileContent = 'Hello world!' 23 | 24 | await page.fill(nameInput, fileName) 25 | await page.fill(contentInput, fileContent) 26 | await page.click(submitBtn) 27 | 28 | await page.waitForSelector(`${output}:has-text("/bafkreigaknpexyvxt76zgkitavbwx6ejgfheup5oybpm77f3pxzrvwpfdi")`) 29 | 30 | const outputContent = await page.textContent(output) 31 | expect(outputContent).toContain('https://ipfs.io/ipfs/bafkreigaknpexyvxt76zgkitavbwx6ejgfheup5oybpm77f3pxzrvwpfdi') 32 | expect(outputContent).toContain(fileName) 33 | expect(outputContent).toContain(fileContent) 34 | }) 35 | }) 36 | -------------------------------------------------------------------------------- /examples/helia-webpack/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-webpack", 3 | "version": "1.0.0", 4 | "private": true, 5 | "type": "module", 6 | "description": "Bundle Helia with Webpack", 7 | "keywords": [], 8 | "license": "MIT", 9 | "scripts": { 10 | "clean": "rimraf ./dist", 11 | "build": "webpack --env production", 12 | "serve": "webpack serve --mode=development", 13 | "start": "npm run serve", 14 | "test": "npm run build && test-browser-example test" 15 | }, 16 | "browserslist": [ 17 | "last 1 Chrome version" 18 | ], 19 | "dependencies": { 20 | "@helia/unixfs": "^1.4.1", 21 | "helia": "^2.0.3", 22 | "react": "^18.2.0", 23 | "react-dom": "^18.2.0" 24 | }, 25 | "devDependencies": { 26 | "@babel/core": "^7.13.10", 27 | "@babel/preset-env": "^7.13.12", 28 | "@babel/preset-react": "^7.12.13", 29 | "@playwright/test": "^1.12.3", 30 | "babel-loader": "^9.1.2", 31 | "copy-webpack-plugin": "^11.0.0", 32 | "css-loader": "^6.2.0", 33 | "html-webpack-plugin": "^5.3.2", 34 | "node-polyfill-webpack-plugin": "^2.0.1", 35 | "playwright": "^1.12.3", 36 | "rimraf": "^5.0.0", 37 | "style-loader": "^3.1.0", 38 | "test-ipfs-example": "^1.0.0", 39 | "webpack": "^5.45.1", 40 | "webpack-cli": "^5.0.1", 41 | "webpack-dev-server": "^4.6.0", 42 | "webpack-merge": "^5.8.0" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/helia-vite/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/helia-vue/src/HeliaApi/useCommitText.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { inject, ref } from 'vue' 4 | 5 | const encoder = new TextEncoder() 6 | const decoder = new TextDecoder() 7 | 8 | export const useCommitText = () => { 9 | const cid = ref() 10 | const commitedText = ref() 11 | const { loading, error, helia, fs } = inject('HeliaProvider') 12 | 13 | const commitText = async (text) => { 14 | console.log('text', text) 15 | if (error.value.length === 0 && !loading.value) { 16 | try { 17 | const res = await fs.value.addBytes( 18 | encoder.encode(text), 19 | helia.value.blockstore 20 | ) 21 | cid.value = res 22 | } catch (e) { 23 | console.error(e) 24 | } 25 | } else { 26 | console.log('please wait for helia to start') 27 | } 28 | } 29 | 30 | const fetchCommitedText = async () => { 31 | let text = '' 32 | console.log(cid) 33 | if (error.value.length === 0 && !loading.value && cid.value) { 34 | try { 35 | for await (const chunk of fs.value.cat(cid.value)) { 36 | text += decoder.decode(chunk, { 37 | stream: true 38 | }) 39 | } 40 | commitedText.value = text 41 | } catch (e) { 42 | console.error(e) 43 | } 44 | } else { 45 | console.log('please wait for helia to start') 46 | } 47 | } 48 | 49 | return { cid, commitText, commitedText, fetchCommitedText } 50 | } 51 | -------------------------------------------------------------------------------- /examples/helia-create-car/public/vite.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/helia-vite/src/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | -webkit-text-size-adjust: 100%; 15 | } 16 | 17 | a { 18 | font-weight: 500; 19 | color: #646cff; 20 | text-decoration: inherit; 21 | } 22 | a:hover { 23 | color: #535bf2; 24 | } 25 | 26 | body { 27 | margin: 0; 28 | display: flex; 29 | min-width: 320px; 30 | min-height: 100vh; 31 | } 32 | 33 | h1 { 34 | font-size: 3.2em; 35 | line-height: 1.1; 36 | } 37 | 38 | button { 39 | border-radius: 8px; 40 | border: 1px solid transparent; 41 | padding: 0.6em 1.2em; 42 | font-size: 1em; 43 | font-weight: 500; 44 | font-family: inherit; 45 | background-color: #1a1a1a; 46 | cursor: pointer; 47 | transition: border-color 0.25s; 48 | } 49 | button:hover { 50 | border-color: #646cff; 51 | } 52 | button:focus, 53 | button:focus-visible { 54 | outline: 4px auto -webkit-focus-ring-color; 55 | } 56 | 57 | @media (prefers-color-scheme: light) { 58 | :root { 59 | color: #213547; 60 | background-color: #ffffff; 61 | } 62 | a:hover { 63 | color: #747bff; 64 | } 65 | button { 66 | background-color: #f9f9f9; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-examples", 3 | "version": "1.0.0", 4 | "description": "", 5 | "type": "module", 6 | "scripts": { 7 | "reset": "aegir run clean && aegir clean **/node_modules **/package-lock.json", 8 | "test": "aegir run test", 9 | "clean": "aegir run clean", 10 | "build": "aegir run build", 11 | "lint": "aegir exec aegir -- lint --files '**/*.{js,ts,jsx}' '!**/node_modules/**' '!**/dist/**'", 12 | "lint:fix": "aegir exec aegir -- lint --files '**/*.{js,ts,jsx}' '!**/node_modules/**' '!**/dist/**' --fix", 13 | "dep-check": "aegir run dep-check" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git+https://github.com/ipfs-examples/helia-examples.git" 18 | }, 19 | "author": "", 20 | "license": "ISC", 21 | "bugs": { 22 | "url": "https://github.com/ipfs-examples/helia-examples/issues" 23 | }, 24 | "homepage": "https://github.com/ipfs-examples/helia-examples#readme", 25 | "devDependencies": { 26 | "aegir": "^41.0.4" 27 | }, 28 | "workspaces": [ 29 | "examples/*" 30 | ], 31 | "private": true, 32 | "eslintConfig": { 33 | "extends": [ 34 | "ipfs", 35 | "plugin:react/recommended" 36 | ], 37 | "parserOptions": { 38 | "sourceType": "module", 39 | "ecmaVersion": 2023 40 | }, 41 | "settings": { 42 | "react": { 43 | "version": "detect" 44 | } 45 | } 46 | }, 47 | "@parcel/resolver-default": { 48 | "packageExports": true 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /examples/helia-create-car/src/index.css: -------------------------------------------------------------------------------- 1 | :root { 2 | font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif; 3 | line-height: 1.5; 4 | font-weight: 400; 5 | 6 | color-scheme: light dark; 7 | color: rgba(255, 255, 255, 0.87); 8 | background-color: #242424; 9 | 10 | font-synthesis: none; 11 | text-rendering: optimizeLegibility; 12 | -webkit-font-smoothing: antialiased; 13 | -moz-osx-font-smoothing: grayscale; 14 | -webkit-text-size-adjust: 100%; 15 | } 16 | 17 | a { 18 | font-weight: 500; 19 | color: #646cff; 20 | text-decoration: inherit; 21 | } 22 | a:hover { 23 | color: #535bf2; 24 | } 25 | 26 | body { 27 | margin: 0; 28 | display: flex; 29 | min-width: 320px; 30 | min-height: 100vh; 31 | } 32 | 33 | h1 { 34 | font-size: 3.2em; 35 | line-height: 1.1; 36 | } 37 | 38 | button { 39 | border-radius: 8px; 40 | border: 1px solid transparent; 41 | padding: 0.6em 1.2em; 42 | font-size: 1em; 43 | font-weight: 500; 44 | font-family: inherit; 45 | background-color: #1a1a1a; 46 | cursor: pointer; 47 | transition: border-color 0.25s; 48 | } 49 | button:hover { 50 | border-color: #646cff; 51 | } 52 | button:focus, 53 | button:focus-visible { 54 | outline: 4px auto -webkit-focus-ring-color; 55 | } 56 | 57 | @media (prefers-color-scheme: light) { 58 | :root { 59 | color: #213547; 60 | background-color: #ffffff; 61 | } 62 | a:hover { 63 | color: #747bff; 64 | } 65 | button { 66 | background-color: #f9f9f9; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /examples/helia-vue/src/App.vue: -------------------------------------------------------------------------------- 1 | 19 | 20 | 32 | 33 | 62 | -------------------------------------------------------------------------------- /examples/helia-electron/main.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | const { app, BrowserWindow } = require('electron') 4 | 5 | let mainWindow 6 | 7 | function createWindow () { 8 | mainWindow = new BrowserWindow({ 9 | width: 800, 10 | height: 600, 11 | webPreferences: { 12 | nodeIntegration: true 13 | } 14 | }) 15 | 16 | // and load the index.html of the app. 17 | mainWindow.loadFile('index.html') 18 | 19 | // Open the DevTools. 20 | mainWindow.webContents.openDevTools() 21 | 22 | // Emitted when the window is closed. 23 | mainWindow.on('closed', () => { 24 | mainWindow = null 25 | }) 26 | } 27 | 28 | app.on('ready', async () => { 29 | createWindow() 30 | 31 | try { 32 | // Helia is an ESM-only module but Electron currently only supports CJS 33 | // at the top level, so we have to use dynamic imports to load it 34 | const { createNode } = await import('./helia.mjs') 35 | const node = await createNode() 36 | const id = node.libp2p.peerId 37 | console.log(id) 38 | } catch (err) { 39 | console.error(err) 40 | } 41 | }) 42 | 43 | // Quit when all windows are closed. 44 | app.on('window-all-closed', () => { 45 | if (process.platform !== 'darwin') { 46 | app.quit() 47 | } 48 | }) 49 | 50 | app.on('activate', () => { 51 | if (mainWindow === null) { 52 | createWindow() 53 | } 54 | }) 55 | 56 | // In this file you can include the rest of your app's specific main process 57 | // code. You can also put them in separate files and require them here. 58 | -------------------------------------------------------------------------------- /examples/helia-vite/src/App.jsx: -------------------------------------------------------------------------------- 1 | import { React, useState } from 'react' 2 | import './App.css' 3 | import { useCommitText } from '@/hooks/useCommitText' 4 | import { useHelia } from '@/hooks/useHelia' 5 | 6 | function App () { 7 | const [text, setText] = useState('') 8 | const { error, starting } = useHelia() 9 | const { 10 | cidString, 11 | commitText, 12 | fetchCommittedText, 13 | committedText 14 | } = useCommitText() 15 | 16 | return ( 17 |
18 |
Helia Status
29 | setText(event.target.value)} 33 | type="text" /> 34 | 38 |
textCid: {cidString}
41 | { cidString && (<> 42 | 46 |
Committed Text: {committedText}
49 | ) 50 | } 51 | 52 |
53 | ) 54 | } 55 | 56 | export default App 57 | -------------------------------------------------------------------------------- /examples/helia-parcel/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import { setup, expect } from 'test-ipfs-example/browser' 2 | 3 | // Setup 4 | const test = setup() 5 | 6 | test.describe('bundle ipfs with parcel:', () => { 7 | // DOM 8 | const nameInput = '#file-name' 9 | const contentInput = '#file-content' 10 | const submitBtn = '#add-submit' 11 | const output = '#output' 12 | 13 | test.beforeEach(async ({ servers, page }) => { 14 | await page.goto(servers[0].url) 15 | }) 16 | 17 | /** 18 | * This example is breaks due to `Uncaught Error: Cannot find module 'fs'` when updating helia deps. 19 | * It fails due to `Please configure Helia with a libp2p instance` without upgrading the deps. 20 | * 21 | * @see https://github.com/ipfs-examples/helia-examples/issues/87 22 | */ 23 | test.skip('should initialize a Helia node and add/get a file', async ({ page }) => { 24 | const outputLocator = page.locator(output) 25 | await expect(outputLocator).toHaveText(/Creating Helia node/) 26 | 27 | const fileName = 'test.txt' 28 | const fileContent = 'Hello world!' 29 | 30 | await page.fill(nameInput, fileName) 31 | await page.fill(contentInput, fileContent) 32 | await page.click(submitBtn) 33 | 34 | await page.waitForSelector(`${output}:has-text("/bafkreigaknpexyvxt76zgkitavbwx6ejgfheup5oybpm77f3pxzrvwpfdi")`) 35 | 36 | const outputContent = await page.textContent(output) 37 | expect(outputContent).toContain('https://ipfs.io/ipfs/bafkreigaknpexyvxt76zgkitavbwx6ejgfheup5oybpm77f3pxzrvwpfdi') 38 | expect(outputContent).toContain(fileName) 39 | expect(outputContent).toContain(fileContent) 40 | }) 41 | }) 42 | -------------------------------------------------------------------------------- /examples/helia-vite/src/provider/HeliaProvider.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { unixfs } from '@helia/unixfs' 4 | import { createHelia } from 'helia' 5 | import PropTypes from 'prop-types' 6 | import { 7 | React, 8 | useEffect, 9 | useState, 10 | useCallback, 11 | createContext 12 | } from 'react' 13 | 14 | export const HeliaContext = createContext({ 15 | helia: null, 16 | fs: null, 17 | error: false, 18 | starting: true 19 | }) 20 | 21 | export const HeliaProvider = ({ children }) => { 22 | const [helia, setHelia] = useState(null) 23 | const [fs, setFs] = useState(null) 24 | const [starting, setStarting] = useState(true) 25 | const [error, setError] = useState(null) 26 | 27 | const startHelia = useCallback(async () => { 28 | if (helia) { 29 | console.info('helia already started') 30 | } else if (window.helia) { 31 | console.info('found a windowed instance of helia, populating ...') 32 | setHelia(window.helia) 33 | setFs(unixfs(helia)) 34 | setStarting(false) 35 | } else { 36 | try { 37 | console.info('Starting Helia') 38 | const helia = await createHelia() 39 | setHelia(helia) 40 | setFs(unixfs(helia)) 41 | setStarting(false) 42 | } catch (e) { 43 | console.error(e) 44 | setError(true) 45 | } 46 | } 47 | }, []) 48 | 49 | useEffect(() => { 50 | startHelia() 51 | }, []) 52 | 53 | return ( 54 | {children} 62 | ) 63 | } 64 | 65 | HeliaProvider.propTypes = { 66 | children: PropTypes.any 67 | } 68 | -------------------------------------------------------------------------------- /examples/helia-create-car/src/provider/HeliaProvider.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { unixfs } from '@helia/unixfs' 4 | import { createHelia } from 'helia' 5 | import PropTypes from 'prop-types' 6 | import { 7 | React, 8 | useEffect, 9 | useState, 10 | useCallback, 11 | createContext 12 | } from 'react' 13 | 14 | export const HeliaContext = createContext({ 15 | helia: null, 16 | fs: null, 17 | error: false, 18 | starting: true 19 | }) 20 | 21 | export const HeliaProvider = ({ children }) => { 22 | const [helia, setHelia] = useState(null) 23 | const [fs, setFs] = useState(null) 24 | const [starting, setStarting] = useState(true) 25 | const [error, setError] = useState(null) 26 | 27 | const startHelia = useCallback(async () => { 28 | if (helia) { 29 | console.info('helia already started') 30 | } else if (window.helia) { 31 | console.info('found a windowed instance of helia, populating ...') 32 | setHelia(window.helia) 33 | setFs(unixfs(helia)) 34 | setStarting(false) 35 | } else { 36 | try { 37 | console.info('Starting Helia') 38 | const helia = await createHelia() 39 | setHelia(helia) 40 | setFs(unixfs(helia)) 41 | setStarting(false) 42 | } catch (e) { 43 | console.error(e) 44 | setError(true) 45 | } 46 | } 47 | }, []) 48 | 49 | useEffect(() => { 50 | startHelia() 51 | }, []) 52 | 53 | return ( 54 | {children} 62 | ) 63 | } 64 | 65 | HeliaProvider.propTypes = { 66 | children: PropTypes.node.isRequired 67 | } 68 | -------------------------------------------------------------------------------- /examples/helia-vite/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import { setup, expect } from 'test-ipfs-example/browser' 2 | 3 | // Setup 4 | const test = setup() 5 | 6 | test.describe('Use Helia With react and vite', () => { 7 | // DOM 8 | const heliaStatus = '#heliaStatus' 9 | const textInput = '#textInput' 10 | const commitTextButton = '#commitTextButton' 11 | const cidOutput = '#cidOutput' 12 | const fetchCommittedTextButton = '#fetchCommittedTextButton' 13 | const committedTextOutput = '#committedTextOutput' 14 | 15 | test.beforeEach(async ({ servers, page }) => { 16 | await page.goto(servers[0].url) 17 | }) 18 | 19 | test('should properly initialize a Helia node and add/get a file', async ({ page }) => { 20 | // wait for helia node to be online 21 | const text = 'Hello Helia' 22 | const status = await page.locator(heliaStatus) 23 | await expect(status).toHaveCSS( 24 | 'border-color', 25 | 'rgb(0, 128, 0)', // green 26 | { timeout: 7000 } 27 | ) 28 | 29 | // commit text to the blockstore 30 | await page.fill(textInput, text) 31 | await page.click(commitTextButton) 32 | 33 | await page.waitForSelector(`${cidOutput}:has-text("bafkreig7i5kbqdnoooievvfextf27eoherluxe2pi3j26hu6zpiauydydy")`) 34 | const cidOutputContent = await page.textContent(cidOutput) 35 | 36 | expect(cidOutputContent).toContain('bafkreig7i5kbqdnoooievvfextf27eoherluxe2pi3j26hu6zpiauydydy') 37 | 38 | // retrieve text from blockstore 39 | await page.click(fetchCommittedTextButton) 40 | await page.waitForSelector(`${committedTextOutput}:has-text("${text}")`) 41 | const committedTextOutputLocator = await page.locator(committedTextOutput) 42 | await expect(committedTextOutputLocator).toHaveText(`Committed Text: ${text}`, { timeout: 2000 }) 43 | }) 44 | }) 45 | -------------------------------------------------------------------------------- /examples/helia-101/201-storage.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { unixfs } from '@helia/unixfs' 4 | import { MemoryBlockstore } from 'blockstore-core' 5 | import { createHelia } from 'helia' 6 | 7 | // the blockstore is where we store the blocks that make up files. this blockstore 8 | // stores everything in-memory - other blockstores are available: 9 | // - https://www.npmjs.com/package/blockstore-fs - a filesystem blockstore (for use in node) 10 | // - https://www.npmjs.com/package/blockstore-idb - an IndexDB blockstore (for use in browsers) 11 | // - https://www.npmjs.com/package/blockstore-level - a LevelDB blockstore (for node or browsers, 12 | // though storing files in a database is rarely a good idea) 13 | const blockstore = new MemoryBlockstore() 14 | 15 | // create a Helia node 16 | const helia = await createHelia({ 17 | blockstore 18 | }) 19 | 20 | // create a filesystem on top of Helia, in this case it's UnixFS 21 | const fs = unixfs(helia) 22 | 23 | // we will use this TextEncoder to turn strings into Uint8Arrays 24 | const encoder = new TextEncoder() 25 | 26 | // add the bytes to your node and receive a unique content identifier 27 | const cid = await fs.addBytes(encoder.encode('Hello World 201')) 28 | 29 | console.log('Added file:', cid.toString()) 30 | 31 | // create a second Helia node using the same blockstore 32 | const helia2 = await createHelia({ 33 | blockstore 34 | }) 35 | 36 | // create a second filesystem 37 | const fs2 = unixfs(helia2) 38 | 39 | // this decoder will turn Uint8Arrays into strings 40 | const decoder = new TextDecoder() 41 | let text = '' 42 | 43 | // read the file from the blockstore using the second Helia node 44 | for await (const chunk of fs2.cat(cid)) { 45 | text += decoder.decode(chunk, { 46 | stream: true 47 | }) 48 | } 49 | 50 | console.log('Added file contents:', text) 51 | -------------------------------------------------------------------------------- /examples/helia-vite/src/hooks/useCommitText.jsx: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { useState, useCallback } from 'react' 4 | import { useHelia } from '@/hooks/useHelia' 5 | 6 | const encoder = new TextEncoder() 7 | const decoder = new TextDecoder() 8 | 9 | export const useCommitText = () => { 10 | const { helia, fs, error, starting } = useHelia() 11 | const [cid, setCid] = useState(null) 12 | const [cidString, setCidString] = useState('') 13 | const [committedText, setCommittedText] = useState('') 14 | 15 | const commitText = useCallback(async (text) => { 16 | if (!error && !starting) { 17 | try { 18 | const cid = await fs.addBytes( 19 | encoder.encode(text), 20 | helia.blockstore 21 | ) 22 | setCid(cid) 23 | setCidString(cid.toString()) 24 | console.log('Added file:', cid.toString()) 25 | } catch (e) { 26 | console.error(e) 27 | } 28 | } else { 29 | console.log('please wait for helia to start') 30 | } 31 | }, [error, starting, helia, fs]) 32 | 33 | const fetchCommittedText = useCallback(async () => { 34 | let text = '' 35 | if (!error && !starting) { 36 | try { 37 | for await (const chunk of fs.cat(cid)) { 38 | text += decoder.decode(chunk, { 39 | stream: true 40 | }) 41 | } 42 | setCommittedText(text) 43 | } catch (e) { 44 | console.error(e) 45 | } 46 | } else { 47 | console.log('please wait for helia to start') 48 | } 49 | }, [error, starting, cid, helia, fs]) 50 | // If one forgets to add helia in the dependency array in commitText, additions to the blockstore will not be picked up by react, leading to operations on fs to hang indefinitely in the generator state. As such it would be good practice to ensure to include helia inside the dependency array of all hooks to tell react that the useCallback needs the most up to date helia state 51 | 52 | return { cidString, committedText, commitText, fetchCommittedText } 53 | } 54 | -------------------------------------------------------------------------------- /examples/helia-vue/src/assets/base.css: -------------------------------------------------------------------------------- 1 | /* color palette from */ 2 | :root { 3 | --vt-c-white: #ffffff; 4 | --vt-c-white-soft: #f8f8f8; 5 | --vt-c-white-mute: #f2f2f2; 6 | 7 | --vt-c-black: #181818; 8 | --vt-c-black-soft: #222222; 9 | --vt-c-black-mute: #282828; 10 | 11 | --vt-c-indigo: #2c3e50; 12 | 13 | --vt-c-divider-light-1: rgba(60, 60, 60, 0.29); 14 | --vt-c-divider-light-2: rgba(60, 60, 60, 0.12); 15 | --vt-c-divider-dark-1: rgba(84, 84, 84, 0.65); 16 | --vt-c-divider-dark-2: rgba(84, 84, 84, 0.48); 17 | 18 | --vt-c-text-light-1: var(--vt-c-indigo); 19 | --vt-c-text-light-2: rgba(60, 60, 60, 0.66); 20 | --vt-c-text-dark-1: var(--vt-c-white); 21 | --vt-c-text-dark-2: rgba(235, 235, 235, 0.64); 22 | } 23 | 24 | /* semantic color variables for this project */ 25 | :root { 26 | --color-background: var(--vt-c-white); 27 | --color-background-soft: var(--vt-c-white-soft); 28 | --color-background-mute: var(--vt-c-white-mute); 29 | 30 | --color-border: var(--vt-c-divider-light-2); 31 | --color-border-hover: var(--vt-c-divider-light-1); 32 | 33 | --color-heading: var(--vt-c-text-light-1); 34 | --color-text: var(--vt-c-text-light-1); 35 | 36 | --section-gap: 160px; 37 | } 38 | 39 | @media (prefers-color-scheme: dark) { 40 | :root { 41 | --color-background: var(--vt-c-black); 42 | --color-background-soft: var(--vt-c-black-soft); 43 | --color-background-mute: var(--vt-c-black-mute); 44 | 45 | --color-border: var(--vt-c-divider-dark-2); 46 | --color-border-hover: var(--vt-c-divider-dark-1); 47 | 48 | --color-heading: var(--vt-c-text-dark-1); 49 | --color-text: var(--vt-c-text-dark-2); 50 | } 51 | } 52 | 53 | *, 54 | *::before, 55 | *::after { 56 | box-sizing: border-box; 57 | margin: 0; 58 | position: relative; 59 | font-weight: normal; 60 | } 61 | 62 | body { 63 | min-height: 100vh; 64 | color: var(--color-text); 65 | background: var(--color-background); 66 | transition: color 0.5s, background-color 0.5s; 67 | line-height: 1.6; 68 | font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, 69 | Cantarell, 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; 70 | font-size: 15px; 71 | text-rendering: optimizeLegibility; 72 | -webkit-font-smoothing: antialiased; 73 | -moz-osx-font-smoothing: grayscale; 74 | } 75 | -------------------------------------------------------------------------------- /examples/helia-nextjs/styles/Home.module.css: -------------------------------------------------------------------------------- 1 | .container { 2 | min-height: 100vh; 3 | padding: 0 0.5rem; 4 | display: flex; 5 | flex-direction: column; 6 | justify-content: center; 7 | align-items: center; 8 | height: 100vh; 9 | } 10 | 11 | .main { 12 | padding: 5rem 0; 13 | flex: 1; 14 | display: flex; 15 | flex-direction: column; 16 | justify-content: center; 17 | align-items: center; 18 | } 19 | 20 | .footer { 21 | width: 100%; 22 | height: 100px; 23 | border-top: 1px solid #eaeaea; 24 | display: flex; 25 | justify-content: center; 26 | align-items: center; 27 | } 28 | 29 | .footer a { 30 | display: flex; 31 | justify-content: center; 32 | align-items: center; 33 | flex-grow: 1; 34 | } 35 | 36 | .title a { 37 | color: #0070f3; 38 | text-decoration: none; 39 | } 40 | 41 | .title a:hover, 42 | .title a:focus, 43 | .title a:active { 44 | text-decoration: underline; 45 | } 46 | 47 | .title { 48 | margin: 0; 49 | line-height: 1.15; 50 | font-size: 4rem; 51 | } 52 | 53 | .title, 54 | .description { 55 | text-align: center; 56 | } 57 | 58 | .description { 59 | line-height: 1.5; 60 | font-size: 1.5rem; 61 | } 62 | 63 | .code { 64 | background: #fafafa; 65 | border-radius: 5px; 66 | padding: 0.75rem; 67 | font-size: 1.1rem; 68 | font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, 69 | Bitstream Vera Sans Mono, Courier New, monospace; 70 | } 71 | 72 | .grid { 73 | display: flex; 74 | align-items: center; 75 | justify-content: center; 76 | flex-wrap: wrap; 77 | max-width: 800px; 78 | margin-top: 3rem; 79 | } 80 | 81 | .card { 82 | margin: 1rem; 83 | padding: 1.5rem; 84 | text-align: left; 85 | color: inherit; 86 | text-decoration: none; 87 | border: 1px solid #eaeaea; 88 | border-radius: 10px; 89 | transition: color 0.15s ease, border-color 0.15s ease; 90 | width: 45%; 91 | } 92 | 93 | .card:hover, 94 | .card:focus, 95 | .card:active { 96 | color: #0070f3; 97 | border-color: #0070f3; 98 | } 99 | 100 | .card h2 { 101 | margin: 0 0 1rem 0; 102 | font-size: 1.5rem; 103 | } 104 | 105 | .card p { 106 | margin: 0; 107 | font-size: 1.25rem; 108 | line-height: 1.5; 109 | } 110 | 111 | .logo { 112 | height: 1em; 113 | margin-left: 0.5rem; 114 | } 115 | 116 | @media (max-width: 600px) { 117 | .grid { 118 | width: 100%; 119 | flex-direction: column; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /examples/helia-nestjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "helia-nestjs", 3 | "version": "0.0.1", 4 | "description": "Use Helia with NestJS", 5 | "license": "UNLICENSED", 6 | "type": "module", 7 | "scripts": { 8 | "build": "nest build", 9 | "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", 10 | "start": "nest start", 11 | "start:dev": "nest start --watch", 12 | "start:debug": "nest start --debug --watch", 13 | "start:prod": "node dist/main", 14 | "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", 15 | "test": "NODE_OPTIONS=--experimental-vm-modules jest", 16 | "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch", 17 | "test:cov": "NODE_OPTIONS=--experimental-vm-modules jest --coverage", 18 | "test:debug": "NODE_OPTIONS=--experimental-vm-modules node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", 19 | "test:e2e": "NODE_OPTIONS=--experimental-vm-modules jest --config ./test/jest-e2e.json" 20 | }, 21 | "dependencies": { 22 | "@helia/interface": "^2.0.0", 23 | "@nestjs/common": "^10.0.0", 24 | "@nestjs/core": "^10.0.0", 25 | "@nestjs/platform-express": "^10.0.0", 26 | "helia": "^2.0.3", 27 | "reflect-metadata": "^0.1.13", 28 | "rxjs": "^7.8.1" 29 | }, 30 | "devDependencies": { 31 | "@nestjs/cli": "^10.0.0", 32 | "@nestjs/schematics": "^10.0.0", 33 | "@nestjs/testing": "^10.0.0", 34 | "@types/express": "^4.17.17", 35 | "@types/jest": "^29.5.2", 36 | "@types/node": "^20.3.1", 37 | "@types/supertest": "^2.0.12", 38 | "@typescript-eslint/eslint-plugin": "^5.62.0", 39 | "@typescript-eslint/parser": "^5.62.0", 40 | "eslint": "^8.42.0", 41 | "eslint-config-prettier": "^9.0.0", 42 | "eslint-plugin-prettier": "^5.0.0", 43 | "jest": "^29.5.0", 44 | "prettier": "^3.0.0", 45 | "source-map-support": "^0.5.21", 46 | "supertest": "^6.3.3", 47 | "ts-jest": "^29.1.0", 48 | "ts-loader": "^9.4.3", 49 | "ts-node": "^10.9.1", 50 | "tsconfig-paths": "^4.2.0", 51 | "typescript": "^5.1.3" 52 | }, 53 | "jest": { 54 | "moduleFileExtensions": [ 55 | "js", 56 | "json", 57 | "ts" 58 | ], 59 | "rootDir": "src", 60 | "testRegex": ".*\\.spec\\.ts$", 61 | "transform": { 62 | "^.+\\.(t|j)s$": ["ts-jest", { 63 | "useESM": true 64 | }] 65 | }, 66 | "collectCoverageFrom": [ 67 | "**/*.(t|j)s" 68 | ], 69 | "coverageDirectory": "../coverage", 70 | "testEnvironment": "node", 71 | "preset": "ts-jest/presets/default-esm", 72 | "moduleNameMapper": { 73 | "^(\\.{1,2}/.*)\\.[jt]s$": "$1" 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /examples/helia-101/301-networking.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { noise } from '@chainsafe/libp2p-noise' 4 | import { yamux } from '@chainsafe/libp2p-yamux' 5 | import { unixfs } from '@helia/unixfs' 6 | import { bootstrap } from '@libp2p/bootstrap' 7 | import { tcp } from '@libp2p/tcp' 8 | import { MemoryBlockstore } from 'blockstore-core' 9 | import { MemoryDatastore } from 'datastore-core' 10 | import { createHelia } from 'helia' 11 | import { createLibp2p } from 'libp2p' 12 | import { identifyService } from 'libp2p/identify' 13 | 14 | async function createNode () { 15 | // the blockstore is where we store the blocks that make up files 16 | const blockstore = new MemoryBlockstore() 17 | 18 | // application-specific data lives in the datastore 19 | const datastore = new MemoryDatastore() 20 | 21 | // libp2p is the networking layer that underpins Helia 22 | const libp2p = await createLibp2p({ 23 | datastore, 24 | addresses: { 25 | listen: [ 26 | '/ip4/127.0.0.1/tcp/0' 27 | ] 28 | }, 29 | transports: [ 30 | tcp() 31 | ], 32 | connectionEncryption: [ 33 | noise() 34 | ], 35 | streamMuxers: [ 36 | yamux() 37 | ], 38 | peerDiscovery: [ 39 | bootstrap({ 40 | list: [ 41 | '/dnsaddr/bootstrap.libp2p.io/p2p/QmNnooDu7bfjPFoTZYxMNLWUQJyrVwtbZg5gBMjTezGAJN', 42 | '/dnsaddr/bootstrap.libp2p.io/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa', 43 | '/dnsaddr/bootstrap.libp2p.io/p2p/QmbLHAnMoJPWSCR5Zhtx6BHJX9KiKNN6tpvbUcqanj75Nb', 44 | '/dnsaddr/bootstrap.libp2p.io/p2p/QmcZf59bWwK5XFi76CZX8cbJ4BhTzzA3gU1ZjYZcYW3dwt' 45 | ] 46 | }) 47 | ], 48 | services: { 49 | identify: identifyService() 50 | } 51 | }) 52 | 53 | return await createHelia({ 54 | datastore, 55 | blockstore, 56 | libp2p 57 | }) 58 | } 59 | 60 | // create two helia nodes 61 | const node1 = await createNode() 62 | const node2 = await createNode() 63 | 64 | // connect them together 65 | const multiaddrs = node2.libp2p.getMultiaddrs() 66 | await node1.libp2p.dial(multiaddrs[0]) 67 | 68 | // create a filesystem on top of Helia, in this case it's UnixFS 69 | const fs = unixfs(node1) 70 | 71 | // we will use this TextEncoder to turn strings into Uint8Arrays 72 | const encoder = new TextEncoder() 73 | 74 | // add the bytes to your node and receive a unique content identifier 75 | const cid = await fs.addBytes(encoder.encode('Hello World 301')) 76 | 77 | console.log('Added file:', cid.toString()) 78 | 79 | // create a filesystem on top of the second Helia node 80 | const fs2 = unixfs(node2) 81 | 82 | // this decoder will turn Uint8Arrays into strings 83 | const decoder = new TextDecoder() 84 | let text = '' 85 | 86 | // use the second Helia node to fetch the file from the first Helia node 87 | for await (const chunk of fs2.cat(cid)) { 88 | text += decoder.decode(chunk, { 89 | stream: true 90 | }) 91 | } 92 | 93 | console.log('Fetched file contents:', text) 94 | -------------------------------------------------------------------------------- /examples/helia-webpack/src/ipfs-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | branches: 9 | - '**' 10 | 11 | concurrency: 12 | group: ${{ github.head_ref || github.ref_name }} 13 | cancel-in-progress: true 14 | 15 | jobs: 16 | examples: 17 | runs-on: ubuntu-latest 18 | name: Test ${{ matrix.project }} 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | project: 23 | - helia-101 24 | - helia-cjs 25 | - helia-electron 26 | - helia-esbuild 27 | - helia-jest 28 | - helia-jest-typescript 29 | - helia-nestjs 30 | - helia-nextjs 31 | - helia-parcel 32 | - helia-script-tag 33 | - helia-ts-node 34 | - helia-typescript 35 | - helia-vite 36 | - helia-vue 37 | - helia-webpack 38 | - helia-create-car 39 | defaults: 40 | run: 41 | working-directory: examples/${{ matrix.project }} 42 | steps: 43 | - uses: actions/checkout@v3 44 | - uses: actions/setup-node@v3 45 | with: 46 | node-version: lts/* 47 | - name: Install dependencies 48 | run: npm install 49 | - name: Install Playwright 50 | run: npx -y playwright install --with-deps 51 | - name: Run tests 52 | run: npm run test 53 | env: 54 | CI: true 55 | 56 | monorepo: 57 | runs-on: ubuntu-latest 58 | name: Test monorepo 59 | steps: 60 | - uses: actions/checkout@v3 61 | - uses: actions/setup-node@v3 62 | with: 63 | node-version: lts/* 64 | - name: Install dependencies 65 | run: npm install 66 | - name: Install Playwright 67 | run: npx -y playwright install --with-deps 68 | - name: Run linting 69 | run: npm run lint 70 | env: 71 | CI: true 72 | - name: Run tests 73 | run: npm run test 74 | env: 75 | CI: true 76 | 77 | push-changes: 78 | name: Push changes 79 | runs-on: ubuntu-latest 80 | needs: [monorepo, examples] 81 | if: github.event_name == 'push' && github.ref == 'refs/heads/main' 82 | strategy: 83 | fail-fast: true 84 | matrix: 85 | project: 86 | - helia-101 87 | - helia-cjs 88 | - helia-electron 89 | - helia-esbuild 90 | - helia-jest 91 | - helia-jest-typescript 92 | - helia-nestjs 93 | - helia-parcel 94 | - helia-nextjs 95 | - helia-script-tag 96 | - helia-ts-node 97 | - helia-typescript 98 | - helia-vite 99 | - helia-vue 100 | - helia-webpack 101 | - helia-create-car 102 | steps: 103 | - uses: convictional/trigger-workflow-and-wait@f69fa9eedd3c62a599220f4d5745230e237904be 104 | with: 105 | owner: ipfs-examples 106 | repo: ${{ matrix.project }} 107 | github_token: ${{ secrets.REPO_PULL_TOKEN }} 108 | workflow_file_name: sync.yml 109 | -------------------------------------------------------------------------------- /examples/helia-create-car/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import { createReadStream } from 'node:fs' 2 | import { unixfs } from '@helia/unixfs' 3 | import { CarReader } from '@ipld/car' 4 | import { createHelia } from 'helia' 5 | import { setup, expect } from 'test-ipfs-example/browser' 6 | 7 | // Setup 8 | const test = setup() 9 | 10 | const filesToUpload = [ 11 | './public/helia-create-car-demo.gif', 12 | './public/vite.svg' 13 | ] 14 | 15 | const expectedCarCID = 'bafybeifsknwjwoby7gmnqlzj236rcq47q5pskkum7svsevsod5a74caxry' 16 | 17 | test.describe('Use Helia With react and vite', () => { 18 | // DOM 19 | const heliaStatus = '#heliaStatus' 20 | const fileInput = '#FileUploaderInput' 21 | const downloadCarFileButton = '#downloadCarFile' 22 | const cidOutput = '#carFileCID' 23 | 24 | // async dependent variables 25 | let expectedCIDs 26 | let helia 27 | let heliaFs 28 | 29 | test.beforeEach(async ({ servers, page }) => { 30 | await page.goto(servers[0].url) 31 | 32 | helia = await createHelia({ 33 | start: false 34 | }) 35 | heliaFs = unixfs(helia) 36 | 37 | expectedCIDs = await Promise.all(filesToUpload.map(async (file) => { 38 | const cid = await heliaFs.addByteStream(createReadStream(file)) 39 | return cid.toString() 40 | })) 41 | }) 42 | 43 | test('files can be converted to a valid car file', async ({ page }) => { 44 | // wait for helia node to be online 45 | const status = await page.locator(heliaStatus) 46 | await expect(status).toHaveCSS( 47 | 'border-color', 48 | 'rgb(0, 128, 0)', // green 49 | { timeout: 7000 } 50 | ) 51 | 52 | // select the files to upload 53 | await page.setInputFiles(fileInput, filesToUpload) 54 | 55 | // make sure the output car CID matches the expected CID 56 | await page.waitForSelector(cidOutput) 57 | const cidOutputContent = await page.textContent(cidOutput) 58 | 59 | expect(cidOutputContent).toContain(expectedCarCID) 60 | 61 | // download the car file 62 | const [download] = await Promise.all([ 63 | page.waitForEvent('download'), // wait for download to start 64 | page.click(downloadCarFileButton) 65 | ]) 66 | 67 | // car available for debugging 68 | await download.saveAs('./test-results/helia-create-car-demo.car') 69 | const reader = await CarReader.fromIterable(createReadStream('./test-results/helia-create-car-demo.car')) 70 | 71 | // expect the root of the car file we downloaded and then created from the saved file, to match the 72 | // car file CID listed on the page. 73 | const roots = await reader.getRoots() 74 | expect(roots[0].toString()).toStrictEqual(cidOutputContent) 75 | 76 | // get all the CIDs in the car file 77 | const carFileCids = [] 78 | for await (const cid of reader.cids()) { 79 | carFileCids.push(cid.toString()) 80 | } 81 | expect(carFileCids).toStrictEqual([ 82 | 'bafybeifsknwjwoby7gmnqlzj236rcq47q5pskkum7svsevsod5a74caxry', // root CID 83 | expectedCIDs[0], // CID for filesToUpload[0] 84 | expectedCIDs[1], // CID for filesToUpload[1] 85 | 'bafkreida4xmb4fq4zgkm42xrox4oshesowi35e66kfiqsyv6xerymi3coq', 86 | 'bafkreicz7xeu5jx77kng5tbieuh2bp7ffzjzwn77wpwiy7d3oy6mrbbd4e' 87 | ]) 88 | }) 89 | }) 90 | -------------------------------------------------------------------------------- /examples/helia-vue/src/HeliaApi/useUnixFS.js: -------------------------------------------------------------------------------- 1 | /* eslint-disable no-console */ 2 | 3 | import { inject } from 'vue' 4 | 5 | const encoder = new TextEncoder() 6 | const decoder = new TextDecoder() 7 | 8 | export const useUnixFS = () => { 9 | const { loading, error, fs } = inject('HeliaProvider') 10 | 11 | const getStat = async (dirCid, path) => { 12 | if (error.value.length === 0 && !loading.value) { 13 | try { 14 | const res = await fs.value.stat(dirCid, { 15 | path 16 | }) 17 | const data = { cid: res.cid, blocks: res.blocks } 18 | return { status: 'success', data } 19 | } catch (e) { 20 | console.error(e) 21 | } 22 | } else { 23 | console.log('please wait for helia to start') 24 | } 25 | } 26 | 27 | const addDirectory = async (path) => { 28 | if (error.value.length === 0 && !loading.value) { 29 | try { 30 | const emptyDirCid = await fs.value.addDirectory(path) 31 | const res = await fs.value.mkdir(emptyDirCid, path) 32 | return { status: 'success', data: res } 33 | } catch (e) { 34 | console.error(e) 35 | } 36 | } else { 37 | console.log('please wait for helia to start') 38 | } 39 | } 40 | 41 | const getDirectory = async (dirCid, path) => { 42 | const output = [] 43 | if (error.value.length === 0 && !loading.value) { 44 | try { 45 | if (typeof path !== 'undefined') { 46 | for await (const entry of fs.value.ls(dirCid, { 47 | path 48 | })) { 49 | output.push(entry) 50 | } 51 | } else { 52 | for await (const entry of fs.value.ls(dirCid)) { 53 | output.push(entry) 54 | } 55 | } 56 | return { status: 'success', data: output } 57 | } catch (e) { 58 | console.error(e) 59 | } 60 | } else { 61 | console.log('please wait for helia to start') 62 | } 63 | } 64 | 65 | const addFile = async (name, dirCid, content) => { 66 | if (error.value.length === 0 && !loading.value) { 67 | try { 68 | const res = await fs.value.addFile({ 69 | content: encoder.encode(content) 70 | }) 71 | const updatedCid = await fs.value.cp(res, dirCid, name) 72 | return { status: 'success', data: { dirCid: updatedCid, fileCid: res } } 73 | } catch (e) { 74 | console.error(e) 75 | } 76 | } else { 77 | console.log('please wait for helia to start') 78 | } 79 | } 80 | 81 | const getFile = async (cid) => { 82 | if (error.value.length === 0 && !loading.value) { 83 | let txt = '' 84 | try { 85 | for await (const buf of fs.value.cat(cid)) { 86 | txt += decoder.decode(buf, { 87 | stream: true 88 | }) 89 | } 90 | return { status: 'success', data: txt } 91 | } catch (e) { 92 | console.error(e) 93 | } 94 | } else { 95 | console.log('please wait for helia to start') 96 | } 97 | } 98 | return { 99 | getStat, 100 | addDirectory, 101 | getDirectory, 102 | addFile, 103 | getFile 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /examples/helia-parcel/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Bundle Helia with parcel 8 | 9 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | Helia logo 33 | 34 |
35 | 36 |
37 |

Add data to Helia

38 | 39 |
40 | 41 | 49 | 50 | 51 | 59 | 60 | 77 |
78 | 79 |

Output

80 | 81 |
82 |
83 |
84 |
85 |
86 | 87 |

Listening addresses

88 | 89 |
90 |
91 |
92 | 93 |

Peers

94 | 95 |
96 |
97 |
98 | 99 |

Dial Queue

100 | 101 |
102 |
103 |
104 |
105 | 106 | 107 | -------------------------------------------------------------------------------- /examples/helia-esbuild/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Bundle Helia with esbuild 8 | 9 | 14 | 19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | Helia logo 33 | 34 |
35 | 36 |
37 |

Add data to Helia

38 | 39 |
40 | 41 | 49 | 50 | 51 | 59 | 60 | 77 |
78 | 79 |

Output

80 | 81 |
82 |
83 |
84 |
85 |
86 | 87 |

Listening addresses

88 | 89 |
90 |
91 |
92 | 93 |

Peers

94 | 95 |
96 |
97 |
98 | 99 |

Dial Queue

100 | 101 |
102 |
103 |
104 |
105 | 106 | 107 | -------------------------------------------------------------------------------- /examples/helia-vue/test/index.spec.js: -------------------------------------------------------------------------------- 1 | import { setup, expect } from 'test-ipfs-example/browser' 2 | 3 | // Setup 4 | const test = setup() 5 | 6 | test.describe('Use Helia with Vue', () => { 7 | test.beforeEach(async ({ servers, page }) => { 8 | await page.goto(servers[0].url) 9 | }) 10 | 11 | test('should properly initialize Helia, and add/get a file', async ({ page }) => { 12 | const exampleText = 'Hello Helia' 13 | const exampleDirName = 'newdir' 14 | const exampleFileName = 'test.txt' 15 | 16 | const status = page.locator('#heliaStatus') 17 | await expect(status).toHaveCSS( 18 | 'background-color', 19 | 'rgb(0, 128, 0)', 20 | { timeout: 5000 } 21 | ) 22 | 23 | await page.fill('#commitText', exampleText) 24 | await page.click('#commitTextButton') 25 | const cidOutput = page.locator('#commitTextCidOutput') 26 | await expect(cidOutput).toHaveText( 27 | 'cid: bafkreig7i5kbqdnoooievvfextf27eoherluxe2pi3j26hu6zpiauydydy', 28 | { timeout: 2000 } 29 | ) 30 | 31 | await page.click('#fetchCommitedTextButton') 32 | const textOutput = page.locator('#fetchedCommitedTextOutput') 33 | await expect(textOutput).toHaveText( 34 | `added text: ${exampleText}`, 35 | { timeout: 2000 } 36 | ) 37 | 38 | await page.fill('#newDirInput', exampleDirName) 39 | await page.click('#newDirButton') 40 | const dirOutput = page.locator('#newDirOutput') 41 | await expect(dirOutput).toHaveText( 42 | 'directory Cid: bafybeif5hfzip34o7ocwfg4ge537g7o3nbh3auc3s54l3gsaantucqyyra', 43 | { timeout: 2000 } 44 | ) 45 | 46 | await page.click('#statDirButton') 47 | const statDir = page.locator('#statDirOutput') 48 | await expect(statDir).toContainText( 49 | 'bafybeiczsscdsbs7ffqz55asqdf3smv6klcw3gofszvwlyarci47bgf354', 50 | { timeout: 2000 } 51 | ) 52 | 53 | await page.click('#getDirButton') 54 | const lsDir = await page.locator('#dirListOutput') 55 | await expect(lsDir).toContainText( 56 | 'bafybeif5hfzip34o7ocwfg4ge537g7o3nbh3auc3s54l3gsaantucqyyra/newdir', 57 | { timeout: 2000 } 58 | ) 59 | 60 | await page.fill('#fileNameInput', exampleFileName) 61 | await page.fill('#fileContentInput', exampleText) 62 | await page.click('#newFileButton') 63 | const fileCidOutput = page.locator('#fileCidOutput') 64 | await expect(fileCidOutput).toContainText( 65 | 'bafkreig7i5kbqdnoooievvfextf27eoherluxe2pi3j26hu6zpiauydydy', 66 | { timeout: 2000 } 67 | ) 68 | const updatedDirOutput = page.locator('#updatedDirOutput') 69 | await expect(updatedDirOutput).toContainText( 70 | 'bafybeie6lhtnjvea4j7imyx5lp2c7kfgxjkndc4jjpmcetnkq75lapmgwm', 71 | { timeout: 2000 } 72 | ) 73 | 74 | await page.click('#dirContentsButton') 75 | const dirContentsOutput = page.locator('#dirContentsOutput') 76 | await expect(dirContentsOutput).toContainText( 77 | 'bafkreig7i5kbqdnoooievvfextf27eoherluxe2pi3j26hu6zpiauydydy', 78 | { timeout: 2000 } 79 | ) 80 | await page.click('#fileContentsButton') 81 | const fileContentsOutput = page.locator('#fileContentsOutput') 82 | await expect(fileContentsOutput).toContainText( 83 | exampleText, 84 | { timeout: 2000 } 85 | ) 86 | }) 87 | }) 88 | -------------------------------------------------------------------------------- /examples/helia-nextjs/pages/index.js: -------------------------------------------------------------------------------- 1 | import Head from 'next/head' 2 | import Image from 'next/legacy/image' 3 | import { React } from 'react' 4 | import IpfsComponent from '../components/ipfs' 5 | import styles from '../styles/Home.module.css' 6 | 7 | export default function Home () { 8 | return ( 9 |
10 | 11 | Create Next App 12 | 13 | 14 | 15 | 16 |
17 |

18 | Welcome to Next.js! 19 |

20 | 21 |

22 | Get started by editing{' '} 23 | pages/index.js 24 |

25 | 26 | 75 | 76 | 77 |
78 | 79 | 91 |
92 | ) 93 | } 94 | -------------------------------------------------------------------------------- /examples/helia-script-tag/src/index.js: -------------------------------------------------------------------------------- 1 | /* global Helia, BlockstoreCore, DatastoreCore, HeliaUnixfs */ 2 | 3 | const statusValueEl = document.getElementById('statusValue') 4 | const discoveredPeerCountEl = document.getElementById('discoveredPeerCount') 5 | const connectedPeerCountEl = document.getElementById('connectedPeerCount') 6 | const connectedPeersListEl = document.getElementById('connectedPeersList') 7 | const logEl = document.getElementById('runningLog') 8 | const nodeIdEl = document.getElementById('nodeId') 9 | 10 | document.addEventListener('DOMContentLoaded', async () => { 11 | const helia = window.helia = await instantiateHeliaNode() 12 | window.heliaFs = await HeliaUnixfs.unixfs(helia) 13 | 14 | helia.libp2p.addEventListener('peer:discovery', (evt) => { 15 | window.discoveredPeers.set(evt.detail.id.toString(), evt.detail) 16 | addToLog(`Discovered peer ${evt.detail.id.toString()}`) 17 | }) 18 | 19 | helia.libp2p.addEventListener('peer:connect', (evt) => { 20 | addToLog(`Connected to ${evt.detail.toString()}`) 21 | }) 22 | helia.libp2p.addEventListener('peer:disconnect', (evt) => { 23 | addToLog(`Disconnected from ${evt.detail.toString()}`) 24 | }) 25 | 26 | setInterval(() => { 27 | statusValueEl.innerHTML = helia.libp2p.isStarted() ? 'Online' : 'Offline' 28 | updateConnectedPeers() 29 | updateDiscoveredPeers() 30 | }, 500) 31 | 32 | const id = await helia.libp2p.peerId.toString() 33 | 34 | nodeIdEl.innerHTML = id 35 | 36 | /** 37 | * You can write more code here to use it. 38 | * 39 | * https://github.com/ipfs/helia 40 | * - helia.start 41 | * - helia.stop 42 | * 43 | * https://github.com/ipfs/helia-unixfs 44 | * - heliaFs.addBytes 45 | * - heliaFs.addFile 46 | * - heliaFs.ls 47 | * - heliaFs.cat 48 | */ 49 | }) 50 | 51 | function ms2TimeString (a) { 52 | const k = a % 1e3 53 | const s = a / 1e3 % 60 | 0 54 | const m = a / 6e4 % 60 | 0 55 | const h = a / 36e5 % 24 | 0 56 | 57 | return (h ? (h < 10 ? '0' + h : h) + ':' : '00:') + 58 | (m < 10 ? 0 : '') + m + ':' + 59 | (s < 10 ? 0 : '') + s + ':' + 60 | (k < 100 ? k < 10 ? '00' : 0 : '') + k 61 | } 62 | 63 | const getLogLineEl = (msg) => { 64 | const logLine = document.createElement('span') 65 | logLine.innerHTML = `${ms2TimeString(performance.now())} - ${msg}` 66 | 67 | return logLine 68 | } 69 | const addToLog = (msg) => { 70 | logEl.appendChild(getLogLineEl(msg)) 71 | } 72 | 73 | let heliaInstance = null 74 | const instantiateHeliaNode = async () => { 75 | // application-specific data lives in the datastore 76 | const datastore = new DatastoreCore.MemoryDatastore() 77 | const blockstore = new BlockstoreCore.MemoryBlockstore() 78 | 79 | if (heliaInstance != null) { 80 | return heliaInstance 81 | } 82 | 83 | heliaInstance = await Helia.createHelia({ 84 | datastore, 85 | blockstore 86 | }) 87 | addToLog('Created Helia instance') 88 | 89 | return heliaInstance 90 | } 91 | 92 | window.discoveredPeers = new Map() 93 | 94 | const updateConnectedPeers = () => { 95 | const peers = window.helia.libp2p.getPeers() 96 | connectedPeerCountEl.innerHTML = peers.length 97 | connectedPeersListEl.innerHTML = '' 98 | for (const peer of peers) { 99 | const peerEl = document.createElement('li') 100 | peerEl.innerText = peer.toString() 101 | connectedPeersListEl.appendChild(peerEl) 102 | } 103 | } 104 | 105 | const updateDiscoveredPeers = () => { 106 | discoveredPeerCountEl.innerHTML = window.discoveredPeers.size 107 | } 108 | -------------------------------------------------------------------------------- /examples/helia-vue/src/components/UnixFSManager.vue: -------------------------------------------------------------------------------- 1 | 73 | 104 | -------------------------------------------------------------------------------- /examples/helia-esbuild/src/index.js: -------------------------------------------------------------------------------- 1 | import { unixfs } from '@helia/unixfs' 2 | import { createHelia } from 'helia' 3 | 4 | const App = async () => { 5 | const DOM = { 6 | output: () => document.getElementById('output'), 7 | fileName: () => document.getElementById('file-name'), 8 | fileContent: () => document.getElementById('file-content'), 9 | addBtn: () => document.getElementById('add-submit'), 10 | terminal: () => document.getElementById('terminal'), 11 | peers: () => document.getElementById('peers'), 12 | dialQueue: () => document.getElementById('dialQueue'), 13 | multiaddrs: () => document.getElementById('multiaddrs') 14 | } 15 | 16 | const COLORS = { 17 | active: '#357edd', 18 | success: '#0cb892', 19 | error: '#ea5037' 20 | } 21 | 22 | const scrollToBottom = () => { 23 | const terminal = DOM.terminal() 24 | terminal.scroll({ top: terminal.scrollHeight, behavior: 'smooth' }) 25 | } 26 | 27 | const showStatus = (text, bg, id = null) => { 28 | const log = DOM.output() 29 | 30 | const line = document.createElement('p') 31 | line.innerHTML = text 32 | line.style.color = bg 33 | 34 | if (id) { 35 | line.id = id 36 | } 37 | 38 | log.appendChild(line) 39 | 40 | scrollToBottom(log) 41 | } 42 | 43 | const cat = async (cid) => { 44 | const decoder = new TextDecoder() 45 | let content = '' 46 | 47 | for await (const chunk of fs.cat(cid)) { 48 | content += decoder.decode(chunk, { 49 | stream: true 50 | }) 51 | } 52 | 53 | return content 54 | } 55 | 56 | const store = async (name, content) => { 57 | const id = helia.libp2p.peerId 58 | showStatus(`Helia node peer ID ${id}`, COLORS.active) 59 | 60 | const fileToAdd = { 61 | path: `${name}`, 62 | content: new TextEncoder().encode(content) 63 | } 64 | 65 | showStatus(`Adding file ${fileToAdd.path}`, COLORS.active) 66 | const cid = await fs.addFile(fileToAdd) 67 | 68 | showStatus(`Added ${cid}`, COLORS.success, cid) 69 | showStatus('Reading file', COLORS.active) 70 | 71 | const text = await cat(cid) 72 | 73 | showStatus(`\u2514\u2500 ${name} ${text.toString()}`) 74 | showStatus(`Preview: https://ipfs.io/ipfs/${cid}`, COLORS.success) 75 | } 76 | 77 | // Event listeners 78 | DOM.addBtn().onclick = async (e) => { 79 | e.preventDefault() 80 | let name = DOM.fileName().value 81 | let content = DOM.fileContent().value 82 | 83 | try { 84 | if (name == null || name.trim() === '') { 85 | showStatus('Set default name', COLORS.active) 86 | name = 'test.txt' 87 | } 88 | 89 | if ((content == null || content.trim() === '')) { 90 | showStatus('Set default content', COLORS.active) 91 | content = 'Hello world!' 92 | } 93 | 94 | await store(name, content) 95 | } catch (err) { 96 | showStatus(err.message, COLORS.error) 97 | } 98 | } 99 | 100 | showStatus('Creating Helia node', COLORS.active) 101 | 102 | const helia = await createHelia() 103 | 104 | showStatus('Helia node ready', COLORS.active) 105 | 106 | const fs = unixfs(helia) 107 | 108 | setInterval(() => { 109 | let peers = '' 110 | 111 | for (const connection of helia.libp2p.getConnections()) { 112 | peers += `${connection.remotePeer.toString()}\n` 113 | } 114 | 115 | if (peers === '') { 116 | peers = 'Not connected to any peers' 117 | } 118 | 119 | DOM.peers().innerText = peers 120 | 121 | let dialQueue = '' 122 | 123 | for (const dial of helia.libp2p.getDialQueue()) { 124 | dialQueue += `${dial.peerId} - ${dial.status}\n${dial.multiaddrs.map(ma => ma.toString()).join('\n')}\n` 125 | } 126 | 127 | if (dialQueue === '') { 128 | dialQueue = 'Dial queue empty' 129 | } 130 | 131 | DOM.dialQueue().innerText = dialQueue 132 | 133 | let multiaddrs = '' 134 | 135 | for (const ma of helia.libp2p.getMultiaddrs()) { 136 | multiaddrs += `${ma.toString()}\n` 137 | } 138 | 139 | if (multiaddrs === '') { 140 | multiaddrs = 'Not listening on any addresses' 141 | } 142 | 143 | DOM.multiaddrs().innerText = multiaddrs 144 | }, 500) 145 | } 146 | 147 | App().catch(err => { 148 | console.error(err) // eslint-disable-line no-console 149 | }) 150 | -------------------------------------------------------------------------------- /examples/helia-parcel/src/index.js: -------------------------------------------------------------------------------- 1 | import { unixfs } from '@helia/unixfs' 2 | import { createHelia } from 'helia' 3 | 4 | const App = async () => { 5 | const DOM = { 6 | output: () => document.getElementById('output'), 7 | fileName: () => document.getElementById('file-name'), 8 | fileContent: () => document.getElementById('file-content'), 9 | addBtn: () => document.getElementById('add-submit'), 10 | terminal: () => document.getElementById('terminal'), 11 | peers: () => document.getElementById('peers'), 12 | dialQueue: () => document.getElementById('dialQueue'), 13 | multiaddrs: () => document.getElementById('multiaddrs') 14 | } 15 | 16 | const COLORS = { 17 | active: '#357edd', 18 | success: '#0cb892', 19 | error: '#ea5037' 20 | } 21 | 22 | const scrollToBottom = () => { 23 | const terminal = DOM.terminal() 24 | terminal.scroll({ top: terminal.scrollHeight, behavior: 'smooth' }) 25 | } 26 | 27 | const showStatus = (text, bg, id = null) => { 28 | const log = DOM.output() 29 | 30 | const line = document.createElement('p') 31 | line.innerHTML = text 32 | line.style.color = bg 33 | 34 | if (id) { 35 | line.id = id 36 | } 37 | 38 | log.appendChild(line) 39 | 40 | scrollToBottom(log) 41 | } 42 | 43 | const cat = async (cid) => { 44 | const decoder = new TextDecoder() 45 | let content = '' 46 | 47 | for await (const chunk of fs.cat(cid)) { 48 | content += decoder.decode(chunk, { 49 | stream: true 50 | }) 51 | } 52 | 53 | return content 54 | } 55 | 56 | const store = async (name, content) => { 57 | const id = helia.libp2p.peerId 58 | showStatus(`Helia node peer ID ${id}`, COLORS.active) 59 | 60 | const fileToAdd = { 61 | path: `${name}`, 62 | content: new TextEncoder().encode(content) 63 | } 64 | 65 | showStatus(`Adding file ${fileToAdd.path}`, COLORS.active) 66 | const cid = await fs.addFile(fileToAdd) 67 | 68 | showStatus(`Added ${cid}`, COLORS.success, cid) 69 | showStatus('Reading file', COLORS.active) 70 | 71 | const text = await cat(cid) 72 | 73 | showStatus(`\u2514\u2500 ${name} ${text.toString()}`) 74 | showStatus(`Preview: https://ipfs.io/ipfs/${cid}`, COLORS.success) 75 | } 76 | 77 | // Event listeners 78 | DOM.addBtn().onclick = async (e) => { 79 | e.preventDefault() 80 | let name = DOM.fileName().value 81 | let content = DOM.fileContent().value 82 | 83 | try { 84 | if (name == null || name.trim() === '') { 85 | showStatus('Set default name', COLORS.active) 86 | name = 'test.txt' 87 | } 88 | 89 | if ((content == null || content.trim() === '')) { 90 | showStatus('Set default content', COLORS.active) 91 | content = 'Hello world!' 92 | } 93 | 94 | await store(name, content) 95 | } catch (err) { 96 | showStatus(err.message, COLORS.error) 97 | } 98 | } 99 | 100 | showStatus('Creating Helia node', COLORS.active) 101 | 102 | const helia = await createHelia() 103 | 104 | showStatus('Helia node ready', COLORS.active) 105 | 106 | const fs = unixfs(helia) 107 | 108 | setInterval(() => { 109 | let peers = '' 110 | 111 | for (const connection of helia.libp2p.getConnections()) { 112 | peers += `${connection.remotePeer.toString()}\n` 113 | } 114 | 115 | if (peers === '') { 116 | peers = 'Not connected to any peers' 117 | } 118 | 119 | DOM.peers().innerText = peers 120 | 121 | let dialQueue = '' 122 | 123 | for (const dial of helia.libp2p.getDialQueue()) { 124 | dialQueue += `${dial.peerId} - ${dial.status}\n${dial.multiaddrs.map(ma => ma.toString()).join('\n')}\n` 125 | } 126 | 127 | if (dialQueue === '') { 128 | dialQueue = 'Dial queue empty' 129 | } 130 | 131 | DOM.dialQueue().innerText = dialQueue 132 | 133 | let multiaddrs = '' 134 | 135 | for (const ma of helia.libp2p.getMultiaddrs()) { 136 | multiaddrs += `${ma.toString()}\n` 137 | } 138 | 139 | if (multiaddrs === '') { 140 | multiaddrs = 'Not listening on any addresses' 141 | } 142 | 143 | DOM.multiaddrs().innerText = multiaddrs 144 | }, 500) 145 | } 146 | 147 | App().catch(err => { 148 | console.error(err) // eslint-disable-line no-console 149 | }) 150 | -------------------------------------------------------------------------------- /examples/helia-create-car/src/components/CarCreator.jsx: -------------------------------------------------------------------------------- 1 | // @ts-check 2 | 3 | import { car } from '@helia/car' 4 | import { unixfs } from '@helia/unixfs' 5 | import { CarWriter } from '@ipld/car/writer' 6 | import React, { useCallback, useEffect, useMemo, useState } from 'react' 7 | import { useFiles } from '../hooks/useFiles' 8 | import { useHelia } from '../hooks/useHelia' 9 | 10 | /** 11 | * 12 | * @param {File} file 13 | * @returns {Promise} 14 | */ 15 | async function readFileAsUint8Array (file) { 16 | return new Promise((resolve, reject) => { 17 | const reader = new FileReader() 18 | 19 | reader.onload = () => { 20 | const arrayBuffer = reader.result 21 | if (arrayBuffer != null) { 22 | if (typeof arrayBuffer === 'string') { 23 | const uint8Array = new TextEncoder().encode(arrayBuffer) 24 | resolve(uint8Array) 25 | } else if (arrayBuffer instanceof ArrayBuffer) { 26 | const uint8Array = new Uint8Array(arrayBuffer) 27 | resolve(uint8Array) 28 | } 29 | return 30 | } 31 | reject(new Error('arrayBuffer is null')) 32 | } 33 | 34 | reader.onerror = (error) => { 35 | reject(error) 36 | } 37 | 38 | reader.readAsArrayBuffer(file) 39 | }) 40 | } 41 | 42 | /** 43 | * 44 | * @param {AsyncIterable} carReaderIterable 45 | * @returns {Promise} 46 | */ 47 | async function carWriterOutToBlob (carReaderIterable) { 48 | const parts = [] 49 | for await (const part of carReaderIterable) { 50 | parts.push(part) 51 | } 52 | return new Blob(parts, { type: 'application/car' }) 53 | } 54 | 55 | export default function CarCreator () { 56 | const { files } = useFiles() 57 | const { helia } = useHelia() 58 | const [carBlob, setCarBlob] = useState(/** @type {null | Blob} */(null)) 59 | const [rootCID, setRootCID] = useState(/** @type {null | import('multiformats').CID} */(null)) 60 | const heliaCar = useMemo(() => { 61 | if (helia == null) { 62 | return null 63 | } 64 | return car(helia) 65 | }, [helia]) 66 | const heliaFs = useMemo(() => { 67 | if (helia == null) { 68 | return null 69 | } 70 | return unixfs(helia) 71 | }, [helia]) 72 | 73 | useEffect(() => { 74 | if (heliaFs == null || heliaCar == null) { 75 | return 76 | } 77 | const asyncFn = async () => { 78 | let rootCID = await heliaFs.addDirectory() 79 | for await (const file of files) { 80 | const fileCid = await heliaFs.addBytes(await readFileAsUint8Array(file)) 81 | rootCID = await heliaFs.cp(fileCid, rootCID, file.name) 82 | } 83 | 84 | const { writer, out } = await CarWriter.create(rootCID) 85 | 86 | // don't await yet.. 87 | const carBlob = carWriterOutToBlob(out) 88 | // await the heliaCar.export, where heliaCar will write blocks to the writer 89 | await heliaCar.export(rootCID, writer) 90 | // await the blob since `out` will have things yielded from the heliaCar.export above. 91 | setCarBlob(await carBlob) 92 | setRootCID(rootCID) 93 | } 94 | asyncFn() 95 | 96 | return () => { 97 | // this hook has been detached for some reason.. clear the state 98 | // highly likely that the files provided have changed and we should get rid of whatever CID and car blob we 99 | // may have had previously. 100 | setCarBlob(null) 101 | setRootCID(null) 102 | } 103 | }, [files, heliaFs, heliaCar]) 104 | 105 | const downloadCarFile = useCallback(async () => { 106 | if (carBlob == null) { 107 | return 108 | } 109 | const downloadEl = document.createElement('a') 110 | const blobUrl = window.URL.createObjectURL(carBlob) 111 | downloadEl.href = blobUrl 112 | downloadEl.download = 'test.car' 113 | document.body.appendChild(downloadEl) 114 | downloadEl.click() 115 | window.URL.revokeObjectURL(blobUrl) 116 | }, [carBlob]) 117 | 118 | if (rootCID == null || files.length === 0) { 119 | return null 120 | } 121 | 122 | return ( 123 |
124 |
125 | Car file CID: 126 | {rootCID.toString()} 127 |
128 | 129 |
130 | ) 131 | } 132 | -------------------------------------------------------------------------------- /examples/helia-electron/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Helia logo 4 | 5 |

6 | 7 |

Running Helia in Electron

8 | 9 |

10 | 11 |
12 | Explore the docs 13 | · 14 | View Demo 15 | · 16 | Report Bug 17 | · 18 | Request Feature/Example 19 |

20 | 21 | ## Table of Contents 22 | 23 | - [Table of Contents](#table-of-contents) 24 | - [About The Project](#about-the-project) 25 | - [Getting Started](#getting-started) 26 | - [Prerequisites](#prerequisites) 27 | - [Installation and Running example](#installation-and-running-example) 28 | - [Usage](#usage) 29 | - [Documentation](#documentation) 30 | - [Contributing](#contributing) 31 | - [Want to hack on IPFS?](#want-to-hack-on-ipfs) 32 | 33 | ## About The Project 34 | 35 | - Read the [docs](https://ipfs.github.io/helia/modules/helia.html) 36 | - Look into other [examples](https://github.com/ipfs-examples/helia-examples) to learn how to spawn a Helia node in Node.js and in the Browser 37 | - Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it 38 | - Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs 39 | - Check out https://docs.ipfs.io for tips, how-tos and more 40 | - See https://blog.ipfs.io for news and more 41 | - Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io 42 | 43 | ## Getting Started 44 | 45 | ### Prerequisites 46 | 47 | Make sure you have installed all of the following prerequisites on your development machine: 48 | 49 | - Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed. 50 | - Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager. 51 | 52 | ### Installation and Running example 53 | 54 | ```console 55 | > npm install 56 | > npm start 57 | ``` 58 | 59 | ## Usage 60 | 61 | This example is heavily inspired by [electron-quick-start](https://github.com/electron/electron-quick-start). 62 | 63 | _For more examples, please refer to the [Documentation](#documentation)_ 64 | 65 | ## Documentation 66 | 67 | - [IPFS Primer](https://dweb-primer.ipfs.io/) 68 | - [IPFS Docs](https://docs.ipfs.io/) 69 | - [Tutorials](https://proto.school) 70 | - [More examples](https://github.com/ipfs-examples/helia-examples) 71 | - [API - Helia](https://ipfs.github.io/helia/modules/helia.html) 72 | - [API - @helia/unixfs](https://ipfs.github.io/helia-unixfs/modules/helia.html) 73 | 74 | ## Contributing 75 | 76 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 77 | 78 | 1. Fork the IPFS Project 79 | 2. Create your Feature Branch (`git checkout -b feature/amazing-feature`) 80 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`) 81 | 4. Push to the Branch (`git push origin feature/amazing-feature`) 82 | 5. Open a Pull Request 83 | 84 | ## Want to hack on IPFS? 85 | 86 | [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) 87 | 88 | The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out: 89 | 90 | Read the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md). 91 | 92 | - **Check out existing issues** The [issue list](https://github.com/ipfs/helia/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge 93 | - **Look at the [Helia Roadmap](https://github.com/ipfs/helia/blob/main/ROADMAP.md)** This are the high priority items being worked on right now 94 | - **Perform code reviews** More eyes will help 95 | a. speed the project along 96 | b. ensure quality, and 97 | c. reduce possible future bugs 98 | - **Add tests**. There can never be enough tests 99 | -------------------------------------------------------------------------------- /examples/helia-parcel/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Helia logo 4 | 5 |

6 | 7 |

Helia with parcel

8 | 9 |

10 | 11 |
12 | Explore the docs 13 | · 14 | View Demo 15 | · 16 | Report Bug 17 | · 18 | Request Feature/Example 19 |

20 | 21 | ## Table of Contents 22 | 23 | - [Table of Contents](#table-of-contents) 24 | - [About The Project](#about-the-project) 25 | - [Getting Started](#getting-started) 26 | - [Prerequisites](#prerequisites) 27 | - [Installation and Running example](#installation-and-running-example) 28 | - [Usage](#usage) 29 | - [Documentation](#documentation) 30 | - [Contributing](#contributing) 31 | - [Want to hack on IPFS?](#want-to-hack-on-ipfs) 32 | 33 | ## About The Project 34 | 35 | - Read the [docs](https://ipfs.github.io/helia/modules/helia.html) 36 | - Look into other [examples](https://github.com/ipfs-examples/helia-examples) to learn how to spawn a Helia node in Node.js and in the Browser 37 | - Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it 38 | - Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs 39 | - Check out https://docs.ipfs.io for tips, how-tos and more 40 | - See https://blog.ipfs.io for news and more 41 | - Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io 42 | 43 | ## Getting Started 44 | 45 | ### Prerequisites 46 | 47 | Make sure you have installed all of the following prerequisites on your development machine: 48 | 49 | - Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed. 50 | - Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager. 51 | 52 | ### Installation and Running example 53 | 54 | ```console 55 | > npm install 56 | > npm start 57 | ``` 58 | 59 | Now open your browser at `http://localhost:8888` 60 | 61 | ## Usage 62 | 63 | In this example, you will find a boilerplate you can use to guide yourself into bundling js-ipfs with [parcel](https://parceljs.org/), so that you can use it in your own web app! 64 | 65 | You should see the following: 66 | 67 | ![](./img/1.png) 68 | ![](./img/2.png) 69 | 70 | _For more examples, please refer to the [Documentation](#documentation)_ 71 | 72 | ## Documentation 73 | 74 | - [IPFS Primer](https://dweb-primer.ipfs.io/) 75 | - [IPFS Docs](https://docs.ipfs.io/) 76 | - [Tutorials](https://proto.school) 77 | - [More examples](https://github.com/ipfs-examples/helia-examples) 78 | - [API - Helia](https://ipfs.github.io/helia/modules/helia.html) 79 | - [API - @helia/unixfs](https://ipfs.github.io/helia-unixfs/modules/helia.html) 80 | 81 | ## Contributing 82 | 83 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 84 | 85 | 1. Fork the IPFS Project 86 | 2. Create your Feature Branch (`git checkout -b feature/amazing-feature`) 87 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`) 88 | 4. Push to the Branch (`git push origin feature/amazing-feature`) 89 | 5. Open a Pull Request 90 | 91 | ## Want to hack on IPFS? 92 | 93 | [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) 94 | 95 | The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out: 96 | 97 | Read the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md). 98 | 99 | - **Check out existing issues** The [issue list](https://github.com/ipfs/helia/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge 100 | - **Look at the [Helia Roadmap](https://github.com/ipfs/helia/blob/main/ROADMAP.md)** This are the high priority items being worked on right now 101 | - **Perform code reviews** More eyes will help 102 | a. speed the project along 103 | b. ensure quality, and 104 | c. reduce possible future bugs 105 | - **Add tests**. There can never be enough tests 106 | -------------------------------------------------------------------------------- /examples/helia-esbuild/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Helia logo 4 | 5 |

6 | 7 |

Helia with esbuild

8 | 9 |

10 | 11 |
12 | Explore the docs 13 | · 14 | View Demo 15 | · 16 | Report Bug 17 | · 18 | Request Feature/Example 19 |

20 | 21 | ## Table of Contents 22 | 23 | - [Table of Contents](#table-of-contents) 24 | - [About The Project](#about-the-project) 25 | - [Getting Started](#getting-started) 26 | - [Prerequisites](#prerequisites) 27 | - [Installation and Running example](#installation-and-running-example) 28 | - [Usage](#usage) 29 | - [Documentation](#documentation) 30 | - [Contributing](#contributing) 31 | - [Want to hack on IPFS?](#want-to-hack-on-ipfs) 32 | 33 | ## About The Project 34 | 35 | - Read the [docs](https://ipfs.github.io/helia/modules/helia.html) 36 | - Look into other [examples](https://github.com/ipfs-examples/helia-examples) to learn how to spawn a Helia node in Node.js and in the Browser 37 | - Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it 38 | - Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs 39 | - Check out https://docs.ipfs.io for tips, how-tos and more 40 | - See https://blog.ipfs.io for news and more 41 | - Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io 42 | 43 | ## Getting Started 44 | 45 | ### Prerequisites 46 | 47 | Make sure you have installed all of the following prerequisites on your development machine: 48 | 49 | - Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed. 50 | - Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager. 51 | 52 | ### Installation and Running example 53 | 54 | ```console 55 | > npm install 56 | > npm start 57 | ``` 58 | 59 | Now open your browser at `http://localhost:8888` 60 | 61 | ## Usage 62 | 63 | In this example, you will find a boilerplate you can use to guide yourself into bundling js-ipfs with [esbuild](https://esbuild.github.io/), so that you can use it in your own web app! 64 | 65 | You should see the following: 66 | 67 | ![](./img/1.png) 68 | ![](./img/2.png) 69 | 70 | _For more examples, please refer to the [Documentation](#documentation)_ 71 | 72 | ## Documentation 73 | 74 | - [IPFS Primer](https://dweb-primer.ipfs.io/) 75 | - [IPFS Docs](https://docs.ipfs.io/) 76 | - [Tutorials](https://proto.school) 77 | - [More examples](https://github.com/ipfs-examples/helia-examples) 78 | - [API - Helia](https://ipfs.github.io/helia/modules/helia.html) 79 | - [API - @helia/unixfs](https://ipfs.github.io/helia-unixfs/modules/helia.html) 80 | 81 | ## Contributing 82 | 83 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 84 | 85 | 1. Fork the IPFS Project 86 | 2. Create your Feature Branch (`git checkout -b feature/amazing-feature`) 87 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`) 88 | 4. Push to the Branch (`git push origin feature/amazing-feature`) 89 | 5. Open a Pull Request 90 | 91 | ## Want to hack on IPFS? 92 | 93 | [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) 94 | 95 | The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out: 96 | 97 | Read the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md). 98 | 99 | - **Check out existing issues** The [issue list](https://github.com/ipfs/helia/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge 100 | - **Look at the [Helia Roadmap](https://github.com/ipfs/helia/blob/main/ROADMAP.md)** This are the high priority items being worked on right now 101 | - **Perform code reviews** More eyes will help 102 | a. speed the project along 103 | b. ensure quality, and 104 | c. reduce possible future bugs 105 | - **Add tests**. There can never be enough tests 106 | -------------------------------------------------------------------------------- /examples/helia-webpack/src/app.js: -------------------------------------------------------------------------------- 1 | import { unixfs } from '@helia/unixfs' 2 | import { createHelia } from 'helia' 3 | import React, { useState, useRef } from 'react' 4 | 5 | function App () { 6 | const [output, setOutput] = useState([]) 7 | const [helia, setHelia] = useState(null) 8 | const [fileContent, setFileContent] = useState('') 9 | const [fileName, setFileName] = useState('') 10 | 11 | const terminalEl = useRef(null) 12 | 13 | const COLORS = { 14 | active: '#357edd', 15 | success: '#0cb892', 16 | error: '#ea5037' 17 | } 18 | 19 | const showStatus = (text, color, id) => { 20 | setOutput((prev) => { 21 | return [...prev, 22 | { 23 | content: text, 24 | color, 25 | id 26 | } 27 | ] 28 | }) 29 | 30 | terminalEl.current.scroll({ top: window.terminal.scrollHeight, behavior: 'smooth' }) 31 | } 32 | 33 | const store = async (name, content) => { 34 | let node = helia 35 | 36 | if (!helia) { 37 | showStatus('Creating Helia node...', COLORS.active) 38 | 39 | node = await createHelia() 40 | 41 | setHelia(node) 42 | } 43 | 44 | showStatus(`Connecting to ${node.libp2p.peerId}...`, COLORS.active, node.libp2p.peerId) 45 | 46 | const encoder = new TextEncoder() 47 | 48 | const fileToAdd = { 49 | path: `${name}`, 50 | content: encoder.encode(content) 51 | } 52 | 53 | const fs = unixfs(node) 54 | 55 | showStatus(`Adding file ${fileToAdd.path}...`, COLORS.active) 56 | const cid = await fs.addFile(fileToAdd, node.blockstore) 57 | 58 | showStatus(`Added to ${cid}`, COLORS.success, cid) 59 | showStatus('Reading file...', COLORS.active) 60 | const decoder = new TextDecoder() 61 | let text = '' 62 | 63 | for await (const chunk of fs.cat(cid)) { 64 | text += decoder.decode(chunk, { 65 | stream: true 66 | }) 67 | } 68 | 69 | showStatus(`\u2514\u2500 ${name} ${text}`) 70 | showStatus(`Preview: https://ipfs.io/ipfs/${cid}`, COLORS.success) 71 | } 72 | 73 | const handleSubmit = async (e) => { 74 | e.preventDefault() 75 | 76 | try { 77 | if (fileName == null || fileName.trim() === '') { 78 | throw new Error('File name is missing...') 79 | } 80 | 81 | if ((fileContent == null || fileContent.trim() === '')) { 82 | throw new Error('File content is missing...') 83 | } 84 | 85 | await store(fileName, fileContent) 86 | } catch (err) { 87 | showStatus(err.message, COLORS.error) 88 | } 89 | } 90 | 91 | return ( 92 | <> 93 |
94 | 95 | Helia logo 101 | 102 |
103 | 104 |
105 |

Add data to Helia

106 | 107 |
108 | 109 | setFileName(e.target.value)} 117 | /> 118 | 119 | 120 | setFileContent(e.target.value)} 128 | /> 129 | 130 | 137 |
138 | 139 |

Output

140 | 141 |
142 |
143 |
144 | { output.length > 0 && 145 |
146 | { output.map((log, index) => 147 |

148 | {log.content} 149 |

) 150 | } 151 |
152 | } 153 |
154 |
155 |
156 | 157 | ) 158 | } 159 | 160 | export default App 161 | -------------------------------------------------------------------------------- /examples/helia-nestjs/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Helia logo 4 | 5 |

6 | 7 |

Using Helia inside a NestJS app

8 | 9 |

10 | 11 |
12 | Explore the docs 13 | · 14 | Report Bug 15 | · 16 | Request Feature/Example 17 |

18 | 19 | ## About 20 | 21 | This is an example of how to run [Helia](https://github.com/ipfs/helia) in a [NestJS](https://nestjs.com/) application. 22 | 23 | This demo was created by running the `nest new` command to bootstrap a basic project. 24 | 25 | A few changes to the default project config were necessary: 26 | 27 | 1. Ensure TypeScript outputs ESM and not CJS 28 | - Please see the [helia-typescript](https://github.com/ipfs-examples/helia-typescript) example for more information 29 | 2. Ensure Jest can run TypeScript ESM tests 30 | - Please see the [helia-jest-typescript](https://github.com/ipfs-examples/helia-jest-typescript) example for more information 31 | 32 | ## Getting Started 33 | 34 | ### Prerequisites 35 | 36 | https://github.com/ipfs-examples/helia-examples#prerequisites 37 | 38 | ### Installation and Running example 39 | 40 | ```console 41 | > npm install 42 | > npm start 43 | ``` 44 | 45 | Now open your browser at `http://localhost:3000` 46 | 47 | ### Available Scripts 48 | 49 | In the project directory, you can run: 50 | 51 | #### `npm start` 52 | 53 | Runs the app in the development mode. 54 | 55 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 56 | 57 | The page will reload if you make edits. 58 | 59 | You will also see any lint errors in the console. 60 | 61 | #### `npm run build` 62 | 63 | Builds the app for production to the `dist` folder. 64 | 65 | It correctly bundles in production mode and optimizes the build for the best performance. 66 | 67 | #### `npm test` 68 | 69 | Runs the [Jest](https://www.npmjs.com/package/jest) unit test suite. 70 | 71 | #### `npm run test:e2e` 72 | 73 | Runs the [Jest](https://www.npmjs.com/package/jest) end-to-end test suite. 74 | 75 | ## Usage 76 | 77 | This is a [NestJS](https://nestjs.com/) project bootstrapped with [`nest new $project_name`](https://docs.nestjs.com/#installation) integrated with `helia`. 78 | 79 | You can start editing the app by modifying `src/main.js`. 80 | 81 | ### Learn More 82 | 83 | To learn more about NestJS, take a look at the following resources: 84 | 85 | - [NestJS Documentation](https://docs.nestjs.com/) - learn about NestJS features and API. 86 | 87 | ## Documentation 88 | 89 | - [IPFS Primer](https://dweb-primer.ipfs.io/) 90 | - [IPFS Docs](https://docs.ipfs.io/) 91 | - [Tutorials](https://proto.school) 92 | - [More examples](https://github.com/ipfs-examples/helia-examples) 93 | - [API - Helia](https://ipfs.github.io/helia/modules/helia.html) 94 | - [API - @helia/unixfs](https://ipfs.github.io/helia-unixfs/modules/helia.html) 95 | 96 | ## Contributing 97 | 98 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 99 | 100 | 1. Fork the IPFS Project 101 | 2. Create your Feature Branch (`git checkout -b feature/amazing-feature`) 102 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`) 103 | 4. Push to the Branch (`git push origin feature/amazing-feature`) 104 | 5. Open a Pull Request 105 | 106 | ## Want to hack on IPFS? 107 | 108 | [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) 109 | 110 | The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out: 111 | 112 | Read the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md). 113 | 114 | - **Check out existing issues** The [issue list](https://github.com/ipfs/helia/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge 115 | - **Look at the [Helia Roadmap](https://github.com/ipfs/helia/blob/main/ROADMAP.md)** This are the high priority items being worked on right now 116 | - **Perform code reviews** More eyes will help 117 | a. speed the project along 118 | b. ensure quality, and 119 | c. reduce possible future bugs 120 | - **Add tests**. There can never be enough tests 121 | -------------------------------------------------------------------------------- /examples/helia-webpack/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Helia logo 4 | 5 |

6 | 7 |

Bundle Helia with Webpack

8 | 9 |

10 | 11 |
12 | Explore the docs 13 | · 14 | View Demo 15 | · 16 | Report Bug 17 | · 18 | Request Feature/Example 19 |

20 | 21 | ## Table of Contents 22 | 23 | - [Table of Contents](#table-of-contents) 24 | - [About The Project](#about-the-project) 25 | - [Getting Started](#getting-started) 26 | - [Prerequisites](#prerequisites) 27 | - [Installation and Running example](#installation-and-running-example) 28 | - [Usage](#usage) 29 | - [Documentation](#documentation) 30 | - [Contributing](#contributing) 31 | - [Want to hack on IPFS?](#want-to-hack-on-ipfs) 32 | 33 | ## About The Project 34 | 35 | - Read the [docs](https://ipfs.github.io/helia/modules/helia.html) 36 | - Look into other [examples](https://github.com/ipfs-examples/helia-examples) to learn how to spawn a Helia node in Node.js and in the Browser 37 | - Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it 38 | - Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs 39 | - Check out https://docs.ipfs.io for tips, how-tos and more 40 | - See https://blog.ipfs.io for news and more 41 | - Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io 42 | 43 | ## Getting Started 44 | 45 | ### Prerequisites 46 | 47 | Make sure you have installed all of the following prerequisites on your development machine: 48 | 49 | - Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed. 50 | - Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager. 51 | 52 | ### Installation and Running example 53 | 54 | ```console 55 | > npm install 56 | > npm start 57 | ``` 58 | 59 | Now open your browser at `http://localhost:3000` 60 | 61 | ## Usage 62 | 63 | In this example, you will find a boilerplate you can use to guide yourself into bundling helia with webpack, so that you can use it in your own web app! 64 | 65 | You should see the following: 66 | 67 | ![](./img/1.png) 68 | 69 | _For more examples, please refer to the [Documentation](#documentation)_ 70 | 71 | ## Documentation 72 | 73 | - [IPFS Primer](https://dweb-primer.ipfs.io/) 74 | - [IPFS Docs](https://docs.ipfs.io/) 75 | - [Tutorials](https://proto.school) 76 | - [More examples](https://github.com/ipfs-examples/helia-examples) 77 | - [API - Helia](https://ipfs.github.io/helia/modules/helia.html) 78 | - [API - @helia/unixfs](https://ipfs.github.io/helia-unixfs/modules/helia.html) 79 | 80 | ## Contributing 81 | 82 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 83 | 84 | 1. Fork the IPFS Project 85 | 2. Create your Feature Branch (`git checkout -b feature/amazing-feature`) 86 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`) 87 | 4. Push to the Branch (`git push origin feature/amazing-feature`) 88 | 5. Open a Pull Request 89 | 90 | ## Want to hack on IPFS? 91 | 92 | [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) 93 | 94 | The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out: 95 | 96 | Read the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md). 97 | 98 | - **Check out existing issues** The [issue list](https://github.com/ipfs/helia/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge 99 | - **Look at the [Helia Roadmap](https://github.com/ipfs/helia/blob/main/ROADMAP.md)** This are the high priority items being worked on right now 100 | - **Perform code reviews** More eyes will help 101 | a. speed the project along 102 | b. ensure quality, and 103 | c. reduce possible future bugs 104 | - **Add tests**. There can never be enough tests 105 | 106 | [cid]: https://docs.ipfs.tech/concepts/content-addressing "Content Identifier" 107 | [Uint8Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array 108 | [libp2p]: https://libp2p.io 109 | -------------------------------------------------------------------------------- /examples/helia-webpack/webpack.config.js: -------------------------------------------------------------------------------- 1 | import path from 'path' 2 | import { fileURLToPath } from 'url' 3 | import CopyWebpackPlugin from 'copy-webpack-plugin' 4 | import HtmlWebpackPlugin from 'html-webpack-plugin' 5 | import NodePolyfillPlugin from 'node-polyfill-webpack-plugin' 6 | import webpack from 'webpack' 7 | import { merge } from 'webpack-merge' 8 | 9 | const __dirname = path.dirname(fileURLToPath(import.meta.url)) 10 | 11 | /** 12 | * HMR/Live Reloading broken after Webpack 5 rc.0 -> rc.1 update 13 | * https://github.com/webpack/webpack-dev-server/issues/2758 14 | * 15 | * target: 'web' for the moment under your development mode. 16 | */ 17 | 18 | const paths = { 19 | // Source files 20 | src: path.resolve(__dirname, './src'), 21 | 22 | // Production build files 23 | build: path.resolve(__dirname, './dist'), 24 | 25 | // Static files that get copied to build folder 26 | public: path.resolve(__dirname, './public') 27 | } 28 | 29 | /** 30 | * @type {Partial} 31 | */ 32 | const prod = { 33 | mode: 'production', 34 | devtool: false, 35 | output: { 36 | path: paths.build, 37 | publicPath: '/', 38 | filename: '[name].[contenthash].bundle.js' 39 | }, 40 | performance: { 41 | hints: false, 42 | maxEntrypointSize: 512000, 43 | maxAssetSize: 512000 44 | }, 45 | // fix: https://github.com/webpack/webpack-dev-server/issues/2758 46 | target: 'browserslist' 47 | } 48 | 49 | /** 50 | * @type {Partial} 51 | */ 52 | const dev = { 53 | // Set the mode to development or production 54 | mode: 'development', 55 | 56 | // Control how source maps are generated 57 | devtool: 'inline-source-map', 58 | 59 | // Where webpack outputs the assets and bundles 60 | output: { 61 | path: paths.build, 62 | filename: '[name].bundle.js', 63 | publicPath: '/' 64 | }, 65 | 66 | // Spin up a server for quick development 67 | devServer: { 68 | historyApiFallback: true, 69 | static: paths.build, 70 | open: true, 71 | compress: true, 72 | hot: true, 73 | port: 3000 74 | }, 75 | 76 | plugins: [ 77 | // Only update what has changed on hot reload 78 | new webpack.HotModuleReplacementPlugin() 79 | ] 80 | } 81 | 82 | /** 83 | * @type {Partial} 84 | */ 85 | const common = { 86 | // Where webpack looks to start building the bundle 87 | entry: [paths.src + '/index.js'], 88 | 89 | // Customize the webpack build process 90 | plugins: [ 91 | // Copies files from target to destination folder 92 | new CopyWebpackPlugin({ 93 | patterns: [ 94 | { 95 | from: `${paths.public}/assets`, 96 | to: 'assets', 97 | globOptions: { 98 | ignore: ['*.DS_Store'] 99 | }, 100 | noErrorOnMissing: true 101 | } 102 | ] 103 | }), 104 | 105 | // fixes Module not found: Error: Can't resolve 'stream' in '.../node_modules/nofilter/lib' 106 | new NodePolyfillPlugin(), 107 | // Note: stream-browserify has assumption about `Buffer` global in its 108 | // dependencies causing runtime errors. This is a workaround to provide 109 | // global `Buffer` until https://github.com/isaacs/core-util-is/issues/29 110 | // is fixed. 111 | new webpack.ProvidePlugin({ 112 | Buffer: ['buffer', 'Buffer'], 113 | process: 'process/browser' 114 | }), 115 | 116 | // Generates an HTML file from a template 117 | // Generates deprecation warning: https://github.com/jantimon/html-webpack-plugin/issues/1501 118 | new HtmlWebpackPlugin({ 119 | title: 'Helia bundle by Webpack', 120 | template: paths.public + '/index.html', // template file 121 | filename: 'index.html', // output file, 122 | minify: false 123 | }) 124 | ], 125 | 126 | // Determine how modules within the project are treated 127 | module: { 128 | rules: [ 129 | // JavaScript: Use Babel to transpile JavaScript files 130 | { 131 | test: /\.js$/, 132 | exclude: /node_modules/, 133 | use: { 134 | loader: 'babel-loader', 135 | options: { 136 | presets: [ 137 | [ 138 | '@babel/preset-env', 139 | { 140 | targets: { 141 | esmodules: true 142 | } 143 | } 144 | ], 145 | '@babel/preset-react' 146 | ] 147 | } 148 | } 149 | }, 150 | 151 | // Images: Copy image files to build folder 152 | { test: /\.(?:ico|gif|png|jpg|jpeg)$/i, type: 'asset/resource' }, 153 | 154 | // Fonts and SVGs: Inline files 155 | { test: /\.(woff(2)?|eot|ttf|otf|svg|)$/, type: 'asset/inline' }, 156 | 157 | { test: /\.(css)$/, use: ['style-loader', 'css-loader'] } 158 | ] 159 | }, 160 | 161 | resolve: { 162 | modules: [paths.src, 'node_modules'], 163 | extensions: ['.js', '.jsx', '.json'], 164 | alias: { 165 | '@': paths.src 166 | } 167 | }, 168 | 169 | // fix: https://github.com/webpack/webpack-dev-server/issues/2758 170 | target: 'web' 171 | } 172 | 173 | export default (cmd) => { 174 | const production = cmd.production 175 | const config = production ? prod : dev 176 | 177 | return merge(common, config) 178 | } 179 | -------------------------------------------------------------------------------- /examples/helia-create-car/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Helia logo 4 | 5 |

6 | 7 |

Helia with React+Vite

8 | 9 |

10 | 11 |
12 | Explore the docs 13 | · 14 | View Demo 15 | · 16 | Report Bug 17 | · 18 | Request Feature/Example 19 |

20 | 21 | ## Table of Contents 22 | 23 | - [Table of Contents](#table-of-contents) 24 | - [About The Project](#about-the-project) 25 | - [Getting Started](#getting-started) 26 | - [Prerequisites](#prerequisites) 27 | - [Installation and Running example](#installation-and-running-example) 28 | - [Usage](#usage) 29 | - [Documentation](#documentation) 30 | - [Contributing](#contributing) 31 | - [Want to hack on IPFS?](#want-to-hack-on-ipfs) 32 | 33 | ## About The Project 34 | 35 | - Read the [docs](https://ipfs.github.io/helia/modules/helia.html) 36 | - Look into other [examples](https://github.com/ipfs-examples/helia-examples) to learn how to spawn a Helia node in Node.js and in the Browser 37 | - Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it 38 | - Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs 39 | - Check out https://docs.ipfs.io for tips, how-tos and more 40 | - See https://blog.ipfs.io for news and more 41 | - Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io 42 | 43 | ## Getting Started 44 | 45 | ### Prerequisites 46 | 47 | Make sure you have installed all of the following prerequisites on your development machine: 48 | 49 | - Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed. 50 | - Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager. 51 | 52 | ### Installation and Running example 53 | 54 | ```console 55 | > npm install 56 | 57 | // then 58 | > npm start 59 | or 60 | > npm run dev 61 | ``` 62 | To run the test 63 | 64 | ```console 65 | npx playwright install 66 | npm run test 67 | ``` 68 | 69 | Now open your browser at `http://localhost:3000` 70 | 71 | ## Usage 72 | 73 | In this example, you will find a boilerplate you can use to guide yourself into creating a car file with helia. 74 | 75 | You should see the following: 76 | 77 | ![](./public/helia-create-car-demo.gif) 78 | 79 | _For more examples, please refer to the [Documentation](#documentation)_ 80 | 81 | ## Documentation 82 | 83 | - [IPFS Primer](https://dweb-primer.ipfs.io/) 84 | - [IPFS Docs](https://docs.ipfs.io/) 85 | - [Tutorials](https://proto.school) 86 | - [More examples](https://github.com/ipfs-examples/helia-examples) 87 | - [API - Helia](https://ipfs.github.io/helia/modules/helia.html) 88 | - [API - @helia/unixfs](https://ipfs.github.io/helia-unixfs/modules/helia.html) 89 | 90 | ## Contributing 91 | 92 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 93 | 94 | 1. Fork the IPFS Project 95 | 2. Create your Feature Branch (`git checkout -b feature/amazing-feature`) 96 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`) 97 | 4. Push to the Branch (`git push origin feature/amazing-feature`) 98 | 5. Open a Pull Request 99 | 100 | ## Want to hack on IPFS? 101 | 102 | [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) 103 | 104 | The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out: 105 | 106 | Read the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md). 107 | 108 | - **Check out existing issues** The [issue list](https://github.com/ipfs/helia/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge 109 | - **Look at the [Helia Roadmap](https://github.com/ipfs/helia/blob/main/ROADMAP.md)** This are the high priority items being worked on right now 110 | - **Perform code reviews** More eyes will help 111 | a. speed the project along 112 | b. ensure quality, and 113 | c. reduce possible future bugs 114 | - **Add tests**. There can never be enough tests 115 | 116 | [cid]: https://docs.ipfs.tech/concepts/content-addressing "Content Identifier" 117 | [Uint8Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array 118 | [libp2p]: https://libp2p.io 119 | -------------------------------------------------------------------------------- /examples/helia-vue/README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Helia logo 4 | 5 |

6 | 7 |

Helia with Vue

8 | 9 |

10 | 11 |
12 | Explore the docs 13 | · 14 | View Demo 15 | · 16 | Report Bug 17 | · 18 | Request Feature/Example 19 |

20 | 21 | ## Table of Contents 22 | 23 | - [Table of Contents](#table-of-contents) 24 | - [About The Project](#about-the-project) 25 | - [Getting Started](#getting-started) 26 | - [Prerequisites](#prerequisites) 27 | - [Installation and Running example](#installation-and-running-example) 28 | - [Usage](#usage) 29 | - [Documentation](#documentation) 30 | - [Contributing](#contributing) 31 | - [Want to hack on IPFS?](#want-to-hack-on-ipfs) 32 | 33 | ## About The Project 34 | 35 | - Read the [docs](https://ipfs.github.io/helia/modules/helia.html) 36 | - Look into other [examples](https://github.com/ipfs-examples/helia-examples) to learn how to spawn a Helia node in Node.js and in the Browser 37 | - Visit https://dweb-primer.ipfs.io to learn about IPFS and the concepts that underpin it 38 | - Head over to https://proto.school to take interactive tutorials that cover core IPFS APIs 39 | - Check out https://docs.ipfs.io for tips, how-tos and more 40 | - See https://blog.ipfs.io for news and more 41 | - Need help? Please ask 'How do I?' questions on https://discuss.ipfs.io 42 | 43 | ## Getting Started 44 | 45 | ### Prerequisites 46 | 47 | Make sure you have installed all of the following prerequisites on your development machine: 48 | 49 | - Git - [Download & Install Git](https://git-scm.com/downloads). OSX and Linux machines typically have this already installed. 50 | - Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager. 51 | 52 | ### Installation and Running example 53 | 54 | ```console 55 | > npm install 56 | > npm start 57 | or 58 | > npm run dev 59 | ``` 60 | To run the test 61 | 62 | ```console 63 | npm run test:e2e 64 | ``` 65 | 66 | Now open your browser at `http://localhost:5173` 67 | 68 | ## Usage 69 | 70 | In this example, you will find a boilerplate you can use to guide yourself into creating a react+vite app with helia, this provides a pattern to reuse the same client across components with the context API and suggests how to integrate it with custom hooks 71 | 72 | You should see the following: 73 | 74 | ![](./public/demo-vue.gif) 75 | 76 | _For more examples, please refer to the [Documentation](#documentation)_ 77 | 78 | ## Documentation 79 | 80 | - [IPFS Primer](https://dweb-primer.ipfs.io/) 81 | - [IPFS Docs](https://docs.ipfs.io/) 82 | - [Tutorials](https://proto.school) 83 | - [More examples](https://github.com/ipfs-examples/helia-examples) 84 | - [API - Helia](https://ipfs.github.io/helia/modules/helia.html) 85 | - [API - @helia/unixfs](https://ipfs.github.io/helia-unixfs/modules/helia.html) 86 | 87 | ## Contributing 88 | 89 | Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**. 90 | 91 | 1. Fork the IPFS Project 92 | 2. Create your Feature Branch (`git checkout -b feature/amazing-feature`) 93 | 3. Commit your Changes (`git commit -a -m 'feat: add some amazing feature'`) 94 | 4. Push to the Branch (`git push origin feature/amazing-feature`) 95 | 5. Open a Pull Request 96 | 97 | ## Want to hack on IPFS? 98 | 99 | [![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md) 100 | 101 | The IPFS implementation in JavaScript needs your help! There are a few things you can do right now to help out: 102 | 103 | Read the [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md) and [JavaScript Contributing Guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING_JS.md). 104 | 105 | - **Check out existing issues** The [issue list](https://github.com/ipfs/helia/issues) has many that are marked as ['help wanted'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3A%22help+wanted%22) or ['difficulty:easy'](https://github.com/ipfs/helia/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Adifficulty%3Aeasy) which make great starting points for development, many of which can be tackled with no prior IPFS knowledge 106 | - **Look at the [Helia Roadmap](https://github.com/ipfs/helia/blob/main/ROADMAP.md)** This are the high priority items being worked on right now 107 | - **Perform code reviews** More eyes will help 108 | a. speed the project along 109 | b. ensure quality, and 110 | c. reduce possible future bugs 111 | - **Add tests**. There can never be enough tests 112 | 113 | [cid]: https://docs.ipfs.tech/concepts/content-addressing "Content Identifier" 114 | [Uint8Array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array 115 | [libp2p]: https://libp2p.io --------------------------------------------------------------------------------