# Start Building

## Contents

shdwDrive SDK

* [Installation](#installation)
* [Local Development](#local-development)
* [Features](#features)
* [Quick Start](#quick-start)
* [Usage Examples](#usage-examples)
* [API Reference](#api-reference)

shdwDrive CLI

* [Features](#features-1)
* [Installation](#installation-1)
* [Configuration](#configuration)
* [Usage](#usage)
* [Development](#development)

## 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

```typescript
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

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

#### Delete a Folder

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

#### List Files

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

#### Delete a File

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

### API Reference

#### `ShdwDriveSDK`

**Constructor Options**

```typescript
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:

* `SHDW_ENDPOINT`: The shdwDrive API endpoint (defaults to <https://v2.shdwdrive.com>)

### Usage

#### Upload a file

```bash
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

```bash
# 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

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

#### List files in a bucket

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

#### Check bucket storage usage

```bash
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
```

2. Install dependencies:

```
cd shdwdrive-v2-cli
npm install
```

3. Build the project:

```
npm run build
```

4. Link the CLI locally:

```
npm link
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.shdwdrive.com/guide/start-building.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
