Start Building

Contents

shdwDrive SDK

shdwDrive CLI

shdwDrive SDK

shdwDrive SDK is a typeScript SDK for interacting with ShdwDrive, providing simple and efficient methods for file operations on the decentralized storage platform.

Installation

# Install from npm
npm install @shdwdrive/sdk

# Or install from repository
git clone https://github.com/GenesysGo/shdwdrive-v2-sdk.git
cd shdwdrive-v2-sdk
npm install
npm run build

Local Development

cd shdwdrive-v2-sdk
npm link
cd your-project
npm link @shdw-drive/sdk

Features

  • 📤 File uploads (supports both small and large files)

  • 📥 File deletion

  • 📋 File listing

  • 📊 Bucket usage statistics

  • 🗂️ Folder creation and management

  • 🔐 Secure message signing

  • ⚡ Progress tracking for uploads

  • 🔄 Multipart upload support for large files

Quick Start

import ShdwDriveSDK from '@shdwdrive/sdk';
// Initialize with wallet
const drive = new ShdwDriveSDK({}, { wallet: yourWalletAdapter });
// Or initialize with keypair
const drive = new ShdwDriveSDK({}, { keypair: yourKeypair });

Usage Examples

Upload a File

const file = new File(['Hello World'], 'hello.txt', { type: 'text/plain' });
const uploadResponse = await drive.uploadFile('your-bucket', file, {
  onProgress: (progress) => {
    console.log(`Upload progress: ${progress.progress}%`);
  }
});
console.log('File uploaded:', uploadResponse.finalized_location);

Create a Folder

const folderResponse = await drive.createFolder('your-bucket', 'folder-name');
console.log('Folder created:', folderResponse.folder_location);

Delete a Folder

const deleteFolderResponse = await drive.deleteFolder('your-bucket', 'folder-url');
console.log('Folder deleted:', deleteFolderResponse.success);

List Files

const files = await drive.listFiles('your-bucket');
console.log('Files in bucket:', files);

Delete a File

const deleteResponse = await drive.deleteFile('your-bucket', 'file-url');
console.log('Delete status:', deleteResponse.success);

API Reference

ShdwDriveSDK

Constructor Options

interface ShdwDriveConfig {
  endpoint?: string; // Optional custom endpoint (defaults to https://v2.shdwdrive.com)
}

// Initialize with either wallet or keypair
new ShdwDriveSDK(config, { wallet: WalletAdapter });
new ShdwDriveSDK(config, { keypair: Keypair });

Methods

  • uploadFile(bucket: string, file: File, options?: FileUploadOptions)

  • deleteFile(bucket: string, fileUrl: string)

  • listFiles(bucket: string)

  • getBucketUsage(bucket: string)

  • createFolder(bucket: string, folderName: string)

  • deleteFolder(bucket: string, folderUrl: string)

shdwDrive CLI

A command-line interface for interacting with shdwDrive storage.

Features

  • 📤 File uploads (supports both small and large files)

  • 📁 Folder support (create, delete, and manage files in folders)

  • 📥 File and folder deletion

  • 📋 File listing

  • 📊 Bucket usage statistics

  • 🔐 Secure message signing

  • 🔄 Multipart upload support for large files

Installation

You can install the CLI globally using npm:

npm install -g @shdwdrive/cli

Or use it directly from the repository:

git clone https://github.com/genesysgo/shdwdrive-v2-cli.git
cd shdwdrive-v2-cli
npm install
npm run build
npm link

Configuration

The CLI uses environment variables for configuration:

Usage

Upload a file

shdw-drive upload \
  --keypair ~/.config/solana/id.json \
  --bucket your-bucket-identifier \
  --file path/to/your/file.txt \
  --folder optional/folder/path

Delete a file

# Delete a file from root of bucket
shdw-drive delete \
  --keypair ~/.config/solana/id.json \
  --bucket your-bucket-identifier \
  --file filename.txt

# Delete a file from a folder
shdw-drive delete \
  --keypair ~/.config/solana/id.json \
  --bucket your-bucket-identifier \
  --file folder/subfolder/filename.jpg

Create a folder

shdw-drive create-folder \
  --keypair ~/.config/solana/id.json \
  --bucket your-bucket-identifier \
  --name my-folder/subfolder

List files in a bucket

shdw-drive list \
  --keypair ~/.config/solana/id.json \
  --bucket your-bucket-identifier

Check bucket storage usage

shdw-drive usage \
  --keypair ~/.config/solana/id.json \
  --bucket your-bucket-identifier

Command Options

Upload Options

  • -k, --keypair - Path to your Solana keypair file

  • -b, --bucket - Your bucket identifier

  • -f, --file - Path to the file you want to upload

  • -F, --folder - (Optional) Folder path within the bucket

Delete Options

  • -k, --keypair - Path to your Solana keypair file

  • -b, --bucket - Your bucket identifier

  • -f, --file - URL or path of the file to delete

Create Folder Options

  • -k, --keypair - Path to your Solana keypair file

  • -b, --bucket - Your bucket identifier

  • -n, --name - Name/path of the folder to create

Delete Folder Options

  • -k, --keypair - Path to your Solana keypair file

  • -b, --bucket - Your bucket identifier

  • -p, --path - Path of the folder to delete

Development

  1. Clone the repository:

git clone https://github.com/genesysgo/shdwdrive-v2-cli.git
  1. Install dependencies:

cd shdwdrive-v2-cli
npm install
  1. Build the project:

npm run build
  1. Link the CLI locally:

npm link

Last updated