Skip to content
/ luna Public

A TypeScript SDK for uploading files & directories to IPFS using Helia

License

Notifications You must be signed in to change notification settings

anistark/luna

Repository files navigation

Luna ☾

luna-b

A TypeScript SDK for uploading files & directories to IPFS using Helia.

NPM

Features

  • File Upload
    • ✅ NodeJs (Backend)
    • ✅ Browser (React, NextJs, etc.)
    • ✅ Pinning via remote URL
  • Folder Upload
    • ✅ NodeJs (Backend)
    • ✅ Pinning via remote URL
  • Fetch File
    • ✅ NodeJs (Backend)
    • ✅ Browser (React, NextJs, etc.)

Install

npm i luna-ipfs

or

yarn add luna-ipfs

or similar for pnpm, bun, etc.

Usage

Import and Initialize

import IPFSUploader from "luna-ipfs";

const uploader = new IPFSUploader();
await uploader.init(); // Initialize Luna

Uses default storage path "./ipfs-blocks" in /var/folders

Upload a File

Node.js

const fileCid = await uploader.uploadFile("./example.txt");
console.log("File uploaded to IPFS:", fileCid);

Browser

const fileInput = document.querySelector("input[type='file']");
fileInput.addEventListener("change", async (event) => {
    const file = event.target.files[0];
    const fileCid = await uploader.uploadFile(file);
    console.log("File uploaded to IPFS:", fileCid);
});

Upload a Directory (Node.js only)

const folderCid = await uploader.uploadDirectory("./my-folder");
console.log("Folder uploaded to IPFS:", folderCid);

Fetch a File from IPFS

const fileContent = await uploader.fetchFile("<CID>");
console.log("Fetched file content:", fileContent);

Stop Helia

Helia instance should be stopped when done using:

await uploader.stop();

This will also cleanup the temp folder used. But your files are permanently saved in IPFS.


💡 Check for available public gateways.


Dev

npm i

Build

npm run build

Test Dev mode

Update file and folder path on test file before proceeding:

npm run test:dev

Maintainer

make release level=patch

with debug

make release level=patch DEBUG=true

⚠️ Under Development ⚠️

About

A TypeScript SDK for uploading files & directories to IPFS using Helia

Resources

License

Stars

Watchers

Forks

Packages

No packages published