Akave is a decentralized protocol for managing on-chain data lakes. This JavaScript library provides an easy-to-use interface for interacting with the Akave Link API.
npm install akave-client
import akave, { Akave, createAkaveInstance } from 'akave-client';
Set the Akave URL via environment variable:
AKAVE_BASE_URL=https://your-akave-endpoint.com
// Create a new bucket
const bucket = await akave.createBucket('my-new-bucket');
console.log(bucket.ID); // Bucket ID
// Get all buckets
const buckets = await akave.listBuckets();
buckets.forEach(bucket => {
console.log(bucket.ID, bucket.CreatedAt);
});
// Upload a file to a specific bucket
const fs = require('fs');
const file = fs.createReadStream('/path/to/file');
const uploadedFile = await akave.uploadFile('bucket-id', file);
console.log(uploadedFile.RootCID);
// Get all files in a bucket
const files = await akave.listFiles('bucket-id');
files.forEach(file => {
console.log(file.Name, file.Size);
});
// Download a specific file
const fileBlob = await akave.downloadFile('bucket-id', 'filename');
// Get download URL for a file
const fileUrl = await akave.getFileURL('bucket-id', 'filename');
console.log(fileUrl);
// Get URLs for all files in a bucket
const allFileUrls = await akave.getAllFileURLs('bucket-id');
// Creating a custom Akave instance
const customAkave = new Akave('https://custom-endpoint.com');
const bucket = await customAkave.createBucket('custom-bucket');
try {
await akave.createBucket('my-bucket');
} catch (error) {
console.error('Failed to create bucket:', error.message);
}
-
AKAVE_BASE_URL
: Base URL for the Akave Link API
- All methods return Promises
- File upload requires a ReadStream