openledger_storage
v0.0.2
Published
Multi-cloud decentralized storage SDK - supports Local, Arweave, Filecoin, Walrus, and BNB Greenfield
Maintainers
Readme
OpenLedger Storage SDK
Multi-cloud decentralized storage SDK that supports Local, Arweave, Filecoin, Walrus, BNB Greenfield, and Shelby.
Features
- Multiple Storage Providers: Seamlessly switch between different storage solutions.
- Unified API: A single, consistent API for all storage operations.
- Easy Configuration: Simple setup for each storage provider.
Supported Providers
- Local File System
- Arweave
- Filecoin
- Walrus
- BNB Greenfield
- Shelby
Installation
npm install openledger_storageRequirements
- Node.js >= 18.0.0
- npm >= 8.0.0
Quick Start
Basic Setup (Read-Only Operations)
For read-only operations, no private key is required:
import { createStorageFactory } from 'openledger_storage';
import fs from 'fs/promises';
async function main() {
// 1. Configure the providers you want to use
const config = {
arweave: {
host: 'arweave.net',
port: 443,
protocol: 'https',
wallet: 'path/to/your/arweave-keyfile.json' // or your wallet object
},
// Add other provider configurations here
};
// 2. Create and initialize the storage factory
const storageFactory = await createStorageFactory(config);
// 3. Get a specific provider
const arweaveProvider = storageFactory.getProvider('arweave');
// 4. Read your file
const fileBuffer = await fs.readFile('path/to/your/file.txt');
const fileName = 'file.txt';
const contentType = 'text/plain';
// 5. Upload the file
try {
const storageId = await arweaveProvider.uploadFile(fileBuffer, fileName, contentType);
console.log(`File uploaded successfully! Storage ID: ${storageId}`);
// 6. Download the file
const downloadedFile = await arweaveProvider.downloadFile(storageId);
await fs.writeFile('downloaded-file.txt', downloadedFile);
console.log('File downloaded successfully!');
} catch (error) {
console.error('Error during file operation:', error);
}
}
main();