# Akave Hackathon intro

Akave ETHGlobal Hackathon

Move your hackathon project data out of the cloud and store it on Akave object storage (Decentralized S3-Compatible ZK-Storage) and Filecoin. Use our simple SDK to easily secure, store, and decentralize your data. The more data the better!

{% hint style="success" %}

### Explaining some key concepts below

{% endhint %}

## Data Flow in Akave Storage

<figure><img src="https://1856480737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7FgogSAXlIRWdEY8j40e%2Fuploads%2Fdqza434a538jI0qyYXIW%2Fimage.png?alt=media&amp;token=abf80d79-0a0c-437c-b783-bd30e52b1783" alt=""><figcaption><p>Akave DataFlow from File/Data to Filecoin</p></figcaption></figure>

In the data flow diagram, we see how files or data are stored through the Akave decentralized storage network and uses decentralized storage like Filecoin. Here’s a breakdown:

1. **File/Data Input**: Users start with files or data, which they want to securely store in a decentralized manner.
2. **Akave SDK and S3-Compatible API**:
   * **Akave SDK**: A software development kit that allows developers to interact with Akave’s storage system easily. It manages data chunking, encryption, and interaction with storage nodes.
   * **S3-Compatible API**: Akave offers an S3-compatible API, meaning users familiar with Amazon S3 storage can interact with Akave’s decentralized storage as if they were working with a traditional cloud storage system.
3. **Data Chunking and Metadata**:
   * Data is broken into chunks to optimize for distributed storage. Each chunk is encrypted and it's associated metadata, which includes information about the file and its structure is stored on-chain.
   * Metadata ensures that chunks can be reassembled into the original file, and it helps manage storage across different nodes.
4. **Storage Nodes and Redundancy**:
   * Akave utilizes a network of nodes, where each chunk of data is stored. Redundant copies of chunks are created across nodes to increase reliability and prevent data loss.
   * The storage process uses concepts such as **Merkle Trees** and **Content Identifiers (CIDs)** to organize and verify data integrity across nodes.
5. **Merkle Trees and CIDs**:
   * **Merkle Tree**: A structure used to verify data integrity. In a Merkle tree, each chunk of data generates a hash. These hashes are combined into parent hashes up the tree, ultimately producing a single root hash that represents the entire data set. If any chunk is modified, the root hash will change, making it easy to detect tampering.
   * **CID (Content Identifier)**: A unique identifier for data stored in decentralized storage. CIDs are derived from the content itself, so they remain constant as long as the data doesn’t change. This enables **immutable storage**, where data cannot be modified without changing its CID, ensuring integrity and authenticity.
6. **Immutable and Decentralized Storage**:
   * **Immutable Storage**: Once data is stored with a CID, it is effectively permanent and unchangeable. If changes are needed, a new CID will be generated, representing the updated content. This ensures data remains secure and unaltered.
   * **Decentralized Storage**: Instead of being stored on a single server, data is distributed across a network of nodes. This increases redundancy, enhances security, and prevents data from being controlled or censored by a central authority.
7. **Filecoin Integration**:
   * **Filecoin**: A decentralized storage network that incentivizes users to share their unused storage space. Akave integrates with Filecoin as an additional storage layer, providing further redundancy and security for long-term data storage.
   * Data chunks can be stored on Filecoin’s storage providers, ensuring they’re accessible even if individual nodes go offline. This additional backup adds another layer of durability to Akave’s decentralized storage system.

## Zoning and Geofencing in Akave

The zoning diagram illustrates how Akave organizes data storage based on geographic zones, which can be useful for geofencing and data localization. Here’s a closer look at each component:

<figure><img src="https://1856480737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7FgogSAXlIRWdEY8j40e%2Fuploads%2FtlYJ5zGlI2AfCNW36WJi%2Fimage.png?alt=media&amp;token=de0a82e4-b771-48bf-aaa9-ab212da3536e" alt=""><figcaption><p>Akave Zoning / Geofencing</p></figcaption></figure>

1. **Akave Zoning**:
   * Zoning allows data to be stored in specific geographic regions or zones based on requirements like data sovereignty, regulatory compliance, or performance needs.
   * Akave nodes are organized into zones (Zone 1, Zone 2, Zone 3, etc.), where each zone may represent a particular geographic area. Data can be stored within a specified zone, ensuring it doesn’t leave that location.
2. **Geofencing**:
   * Geofencing restricts data access or storage to specific locations, which is crucial for regulatory compliance in industries like healthcare or finance. By using zoning, Akave ensures data only resides in permitted regions, meeting privacy and security requirements.
3. **Akave Oasis**:
   * **Akave Oasis** is our blockchain concept in the zoning setup, representing a core node that connects different zones / subnets  together. The Oasis node can coordinate data flow between zones and manage geofencing restrictions, ensuring data storage complies with geographic policies.

#### Summary of Key Concepts

* **CID (Content Identifier)**: A unique identifier generated based on the content of data, ensuring data integrity. Changes to data result in a new CID, enabling immutable storage.
* **Merkle Tree**: A hierarchical hash structure that verifies data integrity. It allows Akave to detect tampering or changes to data stored across nodes.
* **Immutable Storage**: Data stored with a CID is unchangeable. Any modification creates a new CID, preserving the original data’s integrity.
* **Decentralized Storage**: Data is stored across multiple nodes in a network, increasing redundancy and security. No single entity controls the data, which enhances privacy and resilience.
* **Filecoin**: A decentralized storage network used as a backup layer in Akave, ensuring long-term data durability and accessibility through incentives.
* **Zoning and Geofencing**: Akave’s zoning feature allows data to be stored within specific geographic areas, supporting regulatory compliance and data localization requirements.


# Akave SDK CLI

The **Akave SDK CLI** (`akavesdk`) is a powerful command-line tool for managing storage and metadata on Akave’s decentralized network. Designed for developers, this SDK enables bucket and file management, efficient file streaming, and blockchain-based data operations through the IPC API.

{% hint style="success" %}
The preferred method of storing data on the Akave network is by using the blockchain [Integrated storage network and API](/akave-sdk-cli/blockchain-integrated)
{% endhint %}

[Blockchain integrated SDK / CLI](/akave-sdk-cli/blockchain-integrated)

[Streaming non-blockchain integrated SDK / CLI](/akave-sdk-cli/streaming)

[Normal non-blockchain integrated SDK / CLI](/akave-sdk-cli/normal)

The blockchain integrated network is a separate network that uses different nodes to manage and store your data throughout the network.


# Blockchain integrated

The **Akave SDK CLI** (`akavesdk`) is a powerful command-line tool for managing storage and metadata on Akave’s decentralized network. Designed for developers, this SDK enables bucket and file management, efficient file streaming, and blockchain-based data operations through the IPC API.

## Installation

### Requirements

1. **Clone repository**

```bash
git clone https://github.com/akave-ai/akavesdk.git
cd akavesdk
```

2. **Install dependency (**&#x52;equirements: Go 1.22+**)**

Go to : <https://go.dev/doc/install>

### **Mac OS Go install example**

**Mac OS Installation instructions for Go (for all latest OS installation instructions go to <https://go.dev/dl/>)**

#### If you don’t already have Go installed, you can add it with:

```bash
brew install go
```

#### If Go is installed and you need to upgrade to version 1.22+ use:

```bash
brew upgrade go
```

#### After installing or upgrading, confirm the version:&#x20;

```bash
go version
```

### Ubuntu OS Go install example

#### Download package, check online for new version if needed.

```bash
wget https://go.dev/dl/go1.23.2.linux-amd64.tar.gz
```

#### Install Go package

```bash
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.2.linux-amd64.tar.gz
```

#### Set path

Add to `~/.bashrc`

```
export PATH=$PATH:/usr/local/go/bin
```

#### After installing or upgrading, confirm the version:&#x20;

```bash
go version
```

### **Build**

1. **Clone repository**

```bash
git clone https://github.com/akave-ai/akavesdk.git
cd akavesdk
```

2. **Build the SDK CLI**

```bash
make build  # outputs a CLI binary to bin/akavecli
```

### Test & make binary system wide available

To make the `akavesdk` binary executable from any location without specifying the full path, you’ll need to move it to a directory in the system's `PATH`. Here’s how to do it on **Ubuntu**, **macOS**, and other Unix-based systems.

#### 1. Ubuntu/Debian

On Ubuntu and most Debian-based distributions, you can move the binary to `/usr/local/bin/`, which is a common directory for user-installed binaries.

```bash
sudo mv bin/akavesdk /usr/local/bin/
```

#### 2. macOS

macOS also uses `/usr/local/bin/` for user-installed binaries. The same command will work:

```bash
sudo mv bin/akavesdk /usr/local/bin/
```

#### 3. Other Unix-Based Systems (e.g., CentOS, Fedora)

For Red Hat-based distributions like CentOS and Fedora, `/usr/local/bin/` is also typically in the `PATH`, so you can use the same command:

```bash
sudo mv bin/akavesdk /usr/local/bin/
```

#### 4. Alternative Locations (If `/usr/local/bin` is Unavailable)

On some systems, you might also consider `/usr/bin/`. However, this is usually reserved for system binaries, so `/usr/local/bin/` is preferred. If you must use `/usr/bin/`, you can do so like this:

```bash
sudo mv bin/akavesdk /usr/bin/
```

#### Verifying the Installation

After moving the binary, you can confirm it's accessible by all users with:

```bash
akavesdk version
```

This command should run without needing the full path, indicating that it’s correctly in the `PATH`.

## Run

### Get a Wallet Address and Add the Chain to MetaMask

To start, you’ll need an Akave wallet address. Visit <https://faucet.akave.ai>, where you can connect, add the Akave chain to MetaMask, and request funds from the faucet.

<figure><img src="https://1856480737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7FgogSAXlIRWdEY8j40e%2Fuploads%2Fm35BkmzPuyidxgBzyxEe%2FFaucet.gif?alt=media&amp;token=4a35fcbe-81f4-4b2c-9810-9e959bc07f7f" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
**Always be careful when dealing with your private key. Double-check that you’re not hardcoding it anywhere or committing it to Git. Remember: anyone with access to your private key has complete control over your funds.**

Ensure you’re not reusing a private key that’s been deployed on other EVM chains. Each blockchain has its own attack vectors, and reusing keys across chains exposes you to cross-chain vulnerabilities. Keep separate keys to maintain isolation and protect your assets.
{% endhint %}

### Blockchain explorer

<http://explorer.akave.ai>

***

### Node Address

Public endpoint blockchain based network  (`--node-address=connect.akave.ai:5500`)

### IPC API Commands (Preferred)

The IPC API is the recommended approach for interacting with Akave’s decentralized storage. It provides access to Akave’s smart contracts, enabling secure, blockchain-based bucket and file operations.

**Bucket Commands**

* **Create Bucket:** Creates a new bucket using the IPC API.

  ```bash
  akavecli ipc bucket create <bucket-name> --node-address=<node-address> --private-key="your-private-key"
  ```
* **Delete Bucket:** Soft deletes a bucket.

  ```bash
  akavecli ipc bucket delete <bucket-name> --node-address=<node-address> --private-key="your-private-key"
  ```
* **View Bucket:** Retrieves details of a specific bucket.

  ```bash
  akavecli ipc bucket view <bucket-name> --node-address=l<node-address> --private-key="your-private-key"
  ```
* **List Buckets:** Lists all buckets stored in the network.

  ```bash
  akavecli ipc bucket list --node-address=<node-address> --private-key="your-private-key"
  ```

**To secure your key; you can put it in a keyfile and use this: (temporary untill new release)**

```bash
akavecli ipc bucket create <bucket-name> --node-address=<node-address> --private-key "$(cat ~/.key/private.key)"
```

**File Commands**

{% hint style="info" %}
Make sure the minimum file size is 127 bytes! Keep max size to test at 100MB
{% endhint %}

* **List Files:** Lists all files in a specified bucket.

  ```bash
  akavecli ipc file list <bucket-name> --node-address=<node-address> --private-key="your-private-key"
  ```
* **File Info:** Fetches metadata of a specific file.

  ```bash
  akavecli ipc file info <bucket-name> <file-name> --node-address=<node-address> --private-key="your-private-key"
  ```
* **Upload File:** Uploads a file to a specified bucket.

  ```bash
  akavecli ipc file upload <bucket-name> <file-path> --node-address=<node-address> --private-key="your-private-key"
  ```
* **Download File:** Downloads a file from a specified bucket.

  ```bash
  akavecli ipc file download <bucket-name> <file-name> <destination-folder> --node-address=<node-address> --private-key="your-private-key"
  ```

> **Note:** IPC-based commands are highly recommended as they ensure data integrity through blockchain-based operations, making them ideal for decentralized storage use cases.

### Approach to Protect Your Private Key

Using `--private-key "$(cat ~/.key/user.akvf.key)"` offers protection because:

1. **Secure Storage**: The private key is stored in a hidden file (e.g., `~/.key/user.akvf.key`) rather than directly on the command line, reducing its visibility.
2. **Prevents Command History Exposure**: If the private key is directly typed in the command, it may be stored in the shell's history file (e.g., `~/.bash_history`). By using a file reference, only the file path is stored in history, keeping the key itself hidden.
3. **File Permissions**: Saving the private key in a file allows you to restrict permissions (using `chmod 600 ~/.key/user.akvf.key`), ensuring only your user can read it.
4. **Ease of Use and Consistency**: You can reuse the stored key across multiple commands without retyping it, making it convenient for automation and reducing the risk of accidental exposure.

#### How to Implement This Securely

1. **Create and Secure the Private Key File**: Save your private key to a secure, hidden directory:

   ```bash
   bashCopy codemkdir -p ~/.key
   echo "your-private-key-content" > ~/.key/user.akvf.key
   chmod 600 ~/.key/user.akvf.key
   ```

   * `mkdir -p ~/.key` creates the hidden directory if it doesn’t already exist.
   * `echo "your-private-key-content" > ~/.key/user.akvf.key` writes the private key to the file.
   * `chmod 600 ~/.key/user.akvf.key` restricts access so only your user account can read the file.
2. **Example: Use the Command with the Private Key File**:  reference the key file in your command:

   ```bash
   akavecli ipc bucket create workshop --private-key "$(cat ~/.key/user.akvf.key)" --node-address connect.akave.ai:5500
   ```

   * This command reads the private key from `~/.key/user.akvf.key`.
   * It passes the key to the `--private-key` option for `akavecli ipc bucket create`.
   * The `--node-address` flag specifies the node to connect to.

### Steps to Set Up an Environment Variable for Your Private Key

1. **Save the Private Key to an Environment Variable Temporarily**

   You can set the private key as an environment variable in your terminal session. This will store the key in memory for the current session only, and it will not be accessible after you close the terminal.

   ```bash
   export AKAVE_PRIVATE_KEY="$(cat ~/.key/user.akvf.key)"
   ```

   Now, the environment variable `AKAVE_PRIVATE_KEY` holds the private key securely.
2. **Use the Environment Variable in the Command**

   Modify your command to reference the environment variable instead of reading the key from the file:

   ```bash
   akavecli ipc bucket create workshop --private-key "$AKAVE_PRIVATE_KEY" --node-address connect.akave.ai:5500
   ```

   By referencing `$AKAVE_PRIVATE_KEY`, the command will use the key stored in memory rather than reading it directly from a file each time.
3. **Clear the Environment Variable When Done**

   To remove the key from memory, unset the environment variable once you’re finished:

   ```bash
   unset AKAVE_PRIVATE_KEY
   ```

#### Optional: Add the Environment Variable in Your `.bashrc` or `.zshrc`

If you frequently need the private key across sessions, you can add this line to your `.bashrc` or `.zshrc` file:

```bash
export AKAVE_PRIVATE_KEY="$(cat ~/.key/user.akvf.key)"
```

Then, source the file to load the variable:

```bash
source ~/.bashrc  # or source ~/.zshrc
```

Using this approach keeps your private key secure while making it accessible for the command without exposing it on the command line or in history.

***

Good luck with the hackathon, and have fun building with Akave’s decentralized storage SDK CLI!


# Streaming

The **Akave SDK CLI** (`akavesdk`) is a powerful command-line tool for managing storage and metadata on Akave’s decentralized network. Designed for developers, this SDK enables bucket and file management and efficient file streaming.

{% hint style="info" %}
Blockchain-based data operations are done through the [Blockchain based SDK CLI ](/akave-sdk-cli/blockchain-integrated)(preferred)
{% endhint %}

## Installation

### Requirements

1. **Clone repository**

```bash
git clone https://github.com/akave-ai/akavesdk.git
cd akavesdk
```

2. **Install dependency (**&#x52;equirements: Go 1.22+**)**

Go to : <https://go.dev/doc/install>

### **Mac OS Go install example**

**Mac OS Installation instructions for Go (for all latest OS installation instructions go to <https://go.dev/dl/>)**

#### If you don’t already have Go installed, you can add it with:

```bash
brew install go
```

#### If Go is installed and you need to upgrade to version 1.22+ use:

```bash
brew upgrade go
```

#### After installing or upgrading, confirm the version:&#x20;

```bash
go version
```

### Ubuntu OS Go install example

#### Download package, check online for new version if needed.

```bash
wget https://go.dev/dl/go1.23.2.linux-amd64.tar.gz
```

#### Install Go package

```bash
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.2.linux-amd64.tar.gz
```

#### Set path

Add to `~/.bashrc`

```
export PATH=$PATH:/usr/local/go/bin
```

#### After installing or upgrading, confirm the version:&#x20;

```bash
go version
```

### **Build**

1. **Clone repository**

```bash
git clone https://github.com/akave-ai/akavesdk.git
cd akavesdk
```

2. **Build the SDK CLI**

```bash
make build  # outputs a CLI binary to bin/akavecli
```

### Test & make binary system wide available

To make the `akavesdk` binary executable from any location without specifying the full path, you’ll need to move it to a directory in the system's `PATH`. Here’s how to do it on **Ubuntu**, **macOS**, and other Unix-based systems.

#### 1. Ubuntu/Debian

On Ubuntu and most Debian-based distributions, you can move the binary to `/usr/local/bin/`, which is a common directory for user-installed binaries.

```bash
sudo mv bin/akavesdk /usr/local/bin/
```

#### 2. macOS

macOS also uses `/usr/local/bin/` for user-installed binaries. The same command will work:

```bash
sudo mv bin/akavesdk /usr/local/bin/
```

#### 3. Other Unix-Based Systems (e.g., CentOS, Fedora)

For Red Hat-based distributions like CentOS and Fedora, `/usr/local/bin/` is also typically in the `PATH`, so you can use the same command:

```bash
sudo mv bin/akavesdk /usr/local/bin/
```

#### 4. Alternative Locations (If `/usr/local/bin` is Unavailable)

On some systems, you might also consider `/usr/bin/`. However, this is usually reserved for system binaries, so `/usr/local/bin/` is preferred. If you must use `/usr/bin/`, you can do so like this:

```bash
sudo mv bin/akavesdk /usr/bin/
```

#### Verifying the Installation

After moving the binary, you can confirm it's accessible by all users with:

```bash
akavesdk version
```

This command should run without needing the full path, indicating that it’s correctly in the `PATH`.

## Run

{% hint style="info" %}
Make sure the minimum file size is 127 bytes! Keep max size to test at 100MB
{% endhint %}

***

### Streaming API CLI Commands

The CLI also supports direct interaction with the Akave node for bucket and file operations. These commands are useful for high-performance data transfers but do not use the blockchain-based operations provided by the[ IPC API.](/akave-sdk-cli/blockchain-integrated)

### File Management with Streaming API

### Node Address

Public endpoint non-blockchain based network  (`--node-address=connect.akave.ai:5000`)

#### Bucket Management Commands

The streaming API enables efficient file uploads by chunking files and distributing blocks across nodes.

* **List Files:** List all files in a specific bucket.

  ```bash
  akavecli files-streaming list <bucket-name> --node-address=<node-address>
  ```
* **File Info:** Retrieves metadata of a specific file.

  ```bash
  akavecli files-streaming info <bucket-name> <file-name> --node-address=<node-address>
  ```
* **Upload File:** Upload a file by specifying a file path.

  ```bash
  akavecli files-streaming upload <bucket-name> <file-path> --node-address=<node-address>
  ```
* **Download File:** Download a file to a destination folder.

  ```bash
  akavecli files-streaming download <bucket-name> <file-name> <destination-folder> --node-address=<node-address>
  ```
* **Delete File:** Soft deletes a specific file.

  ```bash
  akavecli files-streaming delete <bucket-name> <file-name> --node-address=<node-address>
  ```

***

#### Advanced Streaming File API Overview

The streaming API splits files into chunks (up to 32MB) for efficient uploads across multiple nodes. Files are uploaded through the following steps:

1. **Create File Upload:** Initiates a new file upload with a unique ID.
2. **Upload Chunk:** Each chunk is stored with a receipt for its block locations.
3. **Commit Upload:** Finalizes the file upload, making it available for access.

***

Good luck with the hackathon, and have fun building with Akave’s decentralized storage SDK CLI!


# Normal

The **Akave SDK CLI** (`akavesdk`) is a powerful command-line tool for managing storage and metadata on Akave’s decentralized network. Designed for developers, this SDK enables bucket and file management and efficient file streaming.

{% hint style="info" %}
Blockchain-based data operations are done through the [Blockchain based SDK CLI ](/akave-sdk-cli/blockchain-integrated)(preferred)
{% endhint %}

## Installation

### Requirements

1. **Clone repository**

```bash
git clone https://github.com/akave-ai/akavesdk.git
cd akavesdk
```

2. **Install dependency (**&#x52;equirements: Go 1.22+**)**

Go to : <https://go.dev/doc/install>

### **Mac OS Go install example**

**Mac OS Installation instructions for Go (for all latest OS installation instructions go to <https://go.dev/dl/>)**

#### If you don’t already have Go installed, you can add it with:

```bash
brew install go
```

#### If Go is installed and you need to upgrade to version 1.22+ use:

```bash
brew upgrade go
```

#### After installing or upgrading, confirm the version:&#x20;

```bash
go version
```

### Ubuntu OS Go install example

#### Download package, check online for new version if needed.

```bash
wget https://go.dev/dl/go1.23.2.linux-amd64.tar.gz
```

#### Install Go package

```bash
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.23.2.linux-amd64.tar.gz
```

#### Set path

Add to `~/.bashrc`

```
export PATH=$PATH:/usr/local/go/bin
```

#### After installing or upgrading, confirm the version:&#x20;

```bash
go version
```

### **Build**

1. **Clone repository**

```bash
git clone https://github.com/akave-ai/akavesdk.git
cd akavesdk
```

2. **Build the SDK CLI**

```bash
make build  # outputs a CLI binary to bin/akavecli
```

### Test & make binary system wide available

To make the `akavesdk` binary executable from any location without specifying the full path, you’ll need to move it to a directory in the system's `PATH`. Here’s how to do it on **Ubuntu**, **macOS**, and other Unix-based systems.

#### 1. Ubuntu/Debian

On Ubuntu and most Debian-based distributions, you can move the binary to `/usr/local/bin/`, which is a common directory for user-installed binaries.

```bash
sudo mv bin/akavesdk /usr/local/bin/
```

#### 2. macOS

macOS also uses `/usr/local/bin/` for user-installed binaries. The same command will work:

```bash
sudo mv bin/akavesdk /usr/local/bin/
```

#### 3. Other Unix-Based Systems (e.g., CentOS, Fedora)

For Red Hat-based distributions like CentOS and Fedora, `/usr/local/bin/` is also typically in the `PATH`, so you can use the same command:

```bash
sudo mv bin/akavesdk /usr/local/bin/
```

#### 4. Alternative Locations (If `/usr/local/bin` is Unavailable)

On some systems, you might also consider `/usr/bin/`. However, this is usually reserved for system binaries, so `/usr/local/bin/` is preferred. If you must use `/usr/bin/`, you can do so like this:

```bash
sudo mv bin/akavesdk /usr/bin/
```

#### Verifying the Installation

After moving the binary, you can confirm it's accessible by all users with:

```bash
akavesdk version
```

This command should run without needing the full path, indicating that it’s correctly in the `PATH`.

## Run

{% hint style="info" %}
Make sure the minimum file size is 127 bytes! Keep max size to test at 100MB
{% endhint %}

***

### Standard CLI Commands

The CLI also supports direct interaction with the Akave node for bucket and file operations. These commands are useful for high-performance data transfers but do not use the blockchain-based operations provided by the[ IPC API.](/akave-sdk-cli/blockchain-integrated)

### Node Address

Public endpoint non-blockchain based network  (`--node-address=connect.akave.ai:5000`)

#### Bucket Management Commands

* **Create Bucket:** Creates a new bucket.

  ```bash
  akavecli bucket create <bucket-name> --node-address=<node-address>
  ```
* **View Bucket:** Retrieves details of a specific bucket.

  ```bash
  akavecli bucket view <bucket-name> --node-address=<node-address>
  ```
* **List Buckets:** Lists all buckets in the network.

  ```bash
  akavecli bucket list --node-address=<node-address>
  ```
* **Delete Bucket:** Soft deletes a bucket.

  ```bash
  akavecli bucket delete <bucket-name> --node-address=<node-address>
  ```

***

Good luck with the hackathon, and have fun building with Akave’s decentralized storage SDK CLI!


# JS / Docker example code

## Akave Link API - Hackathon Documentation

Welcome to the Akave Link API! This API wrapper enables seamless integration with Akave's decentralized storage network. Below, you’ll find quick setup steps, examples of how to use each API endpoint with JavaScript, and equivalent `curl` commands.

Github repo for reference : <https://github.com/akave-ai/akavelink>

Installing docker : <https://docs.docker.com/engine/install/>

### Getting Started

#### Step 1: Pull the Docker Image

To start, pull the Akave Link Docker image:

```bash
docker pull akave/akavelink:latest
```

#### Step 2: Get a Wallet Address and Request Funds

* Visit <https://faucet.akave.ai> to obtain a wallet address and add the Akave chain to MetaMask.
* Request funds from the faucet to start experimenting with the Akave Link API.

<figure><img src="https://1856480737-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7FgogSAXlIRWdEY8j40e%2Fuploads%2FWAoWN5DxKfcKcXfydGEs%2FFaucet.gif?alt=media&amp;token=c9fe7952-db76-4288-a4f4-8d97fdbcf4df" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
**Always be careful when dealing with your private key. Double-check that you’re not hardcoding it anywhere or committing it to Git. Remember: anyone with access to your private key has complete control over your funds.**

Ensure you’re not reusing a private key that’s been deployed on other EVM chains. Each blockchain has its own attack vectors, and reusing keys across chains exposes you to cross-chain vulnerabilities. Keep separate keys to maintain isolation and protect your assets.
{% endhint %}

#### Blockchain explorer : <http://explorer.akave.ai>

#### Step 3: Run the Akave Link Container

Run the container and specify the `PRIVATE_KEY` environment variable:

{% hint style="success" %}
With Akavelink we expect you to use the blockchain enabled storage network on port 5500
{% endhint %}

**Node Address Public endpoint (** NODE\_ADDRESS **)  ->  `connect.akave.ai:5500`**

```bash
docker run -d \
  -p 8000:3000 \
  -e NODE_ADDRESS="public_node_address" \
  -e PRIVATE_KEY="your_private_key" \
  akave/akavelink:latest
```

The API will now be running locally at `http://localhost:8000`.

### Setting Up the JavaScript Wrapper

Here's a quick setup to interact with the Akave API using JavaScript:

```javascript
const axios = require('axios');

const API_BASE_URL = 'http://localhost:8000';

async function apiRequest(method, endpoint, data = null) {
  try {
    const response = await axios({
      method,
      url: `${API_BASE_URL}${endpoint}`,
      data,
    });
    console.log(response.data);
  } catch (error) {
    console.error(error.response ? error.response.data : error.message);
  }
}
```

#### Example Usage:

Each section below demonstrates API calls using this wrapper, alongside the `curl` equivalent.

***

### Bucket Operations

#### 1. Create a Bucket

Create a new storage bucket.

**JavaScript Example:**

```javascript
apiRequest('POST', '/buckets', { bucketName: 'myBucket' });
```

**`curl` Command:**

```bash
curl -X POST http://localhost:8000/buckets -H "Content-Type: application/json" -d '{"bucketName": "myBucket"}'
```

#### 2. List Buckets

Retrieve all existing buckets.

**JavaScript Example:**

```javascript
apiRequest('GET', '/buckets');
```

**`curl` Command:**

```bash
curl -X GET http://localhost:8000/buckets
```

#### 3. View Bucket Details

Retrieve details of a specific bucket.

**JavaScript Example:**

```javascript
apiRequest('GET', '/buckets/myBucket');
```

**`curl` Command:**

```bash
curl -X GET http://localhost:8000/buckets/myBucket
```

***

### File Operations

#### 1. List Files in a Bucket

Retrieve a list of files within a bucket.

**JavaScript Example:**

```javascript
apiRequest('GET', '/buckets/myBucket/files');
```

**`curl` Command:**

```bash
curl -X GET http://localhost:8000/buckets/myBucket/files
```

#### 2. Get File Info

Fetch metadata about a specific file.

**JavaScript Example:**

```javascript
apiRequest('GET', '/buckets/myBucket/files/myFile.txt');
```

**`curl` Command:**

```bash
curl -X GET http://localhost:8000/buckets/myBucket/files/myFile.txt
```

#### 3. Upload a File

Upload a file to a bucket.

{% hint style="info" %}
Make sure the minimum file size is 127 bytes! Keep max size to test at 100MB
{% endhint %}

**JavaScript Example (using FormData):**

```javascript
const FormData = require('form-data');
const fs = require('fs');

async function uploadFile(bucketName, filePath) {
  const form = new FormData();
  form.append('file', fs.createReadStream(filePath));
  
  try {
    const response = await axios.post(`${API_BASE_URL}/buckets/${bucketName}/files`, form, {
      headers: form.getHeaders(),
    });
    console.log(response.data);
  } catch (error) {
    console.error(error.response ? error.response.data : error.message);
  }
}

uploadFile('myBucket', './path/to/file.txt');
```

**`curl` Command:**

```bash
curl -X POST http://localhost:8000/buckets/myBucket/files -F file=@/path/to/file.txt
```

#### 4. Download a File

Download a file from a bucket.

**JavaScript Example:**

```javascript
async function downloadFile(bucketName, fileName, outputDir) {
  try {
    const response = await axios.get(`${API_BASE_URL}/buckets/${bucketName}/files/${fileName}/download`, {
      responseType: 'blob',
    });
    console.log(`File downloaded: ${fileName}`);
    fs.writeFileSync(`./${outputDir}/${fileName}`, response.data);
  } catch (error) {
    console.error(error.response ? error.response.data : error.message);
  }
}
```

You can download the file directly in your browser or provide a download url with a public hosted API by using:\
`http(s)://ip-or-dns-name/buckets/:BucketName/files/:FileName/download`

**`curl` Command:**

```bash
curl -X GET http://localhost:8000/buckets/myBucket/files/myFile.txt/download -o myFile.txt
```

Output file extention should be the same as the requested file.

***

### Error Handling

All endpoints return errors in the following format:

```json
{
    "success": false,
    "error": "error message"
}
```

Ensure you handle these responses in your code to capture and process errors effectively.

Good luck with your hackathon, and have fun building with Akave’s decentralized storage API!


