Crypto News

How To Deploy a Feedback API on Aleph Cloud Using Aleph CLI

Aleph Cloud is a web3 supercloud that provides infrastructure for decentralized storage, computing, and AI. It provides Serverless computing, Decentralized storageand Secure the routing message without relying on the traditional centralized server. It also provides a blockchain indexing framework, which allows developers to index data from any blockchain network by seizing the decentralized storage and compute capabilities of the Aleph Network.

Now our hands are dirty. In this article, you will learn how to deploy an API to Aleph Cloud using Aleph CLI.

Prerequiste

  1. Python knowledge
  2. Python and Pip need to be installed on your local machine. You can check the version of your python or pip, use the following commands:
python3 --version //check python version

pip3 --version //check pip version

pip3 install --upgrade pip //to upgrade pip
  1. At least 500 Aleph in your Ethereum or Solana Wallet
  2. A code editor, eg vs code
  3. A folder for your project with a directory structure like this: my-project/ │ ├─ thin app/ │ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └ └

Let's dive in

I -set up the project

  1. I -Install VirtualenV using this command:
pip3 install virtualenv

2. Create a virtual environment using this command:

python3 -m virtualenv venv

3. I activate the virtual environment:

source venv/bin/activate
  1. I -Install all of the following packages:
pip3 install fastapi uvicorn aleph-client

Creating Feedback API

To your main.pyCopy and I -Paste the following code:

from fastapi import FastAPI, Request
from pydantic import BaseModel

app = FastAPI()

# In-memory feedback storage
feedback_store = []

class Feedback(BaseModel):
    dapp: str
    feedback: str

@app.get("/")
async def root():
    return {"message": "Hello World"}

@app.get("/feedback")
async def get_feedback():
    return feedback_store

@app.post("/feedback")
async def submit_feedback(item: Feedback):
    feedback_store.append(item.dict())
    return {"message": "Feedback received"}

Try local

  1. Run the server:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
  1. Then test:
curl -X POST  -H "Content-Type: application/json" -d '{"dapp": "MyCoolDapp", "feedback": "Love the UI!"}'

You should see the result here:

It shows that your API works perfectly

Deploy to Aleph Cloud

You need to create a Aleph CLI account with your private key by following this process:

  1. Create a new account using this command:
aleph account create --private-key TEXT
  1. Enter your private key
  2. Select the chain of your private key

To deploy the project:

  1. I -Compress your main.py File with a .zip file
  2. I -upload the file with this command:
aleph program upload app/main.py.zip main:app
  1. Select the program tier you are going to and accept Runtime Reference

Select based on the amount of tokens you have and the needs of the project

  1. Enter the name of your application
  2. Since our project does not require any quantity and uses a variable environment n
Preset to default chain: SOL
╭─ Pricing: Program ───────────────────────────────────────────────────────────────────────────────╮
│        ╷               ╷       ╷           ╷            ╷                  ╷                     │
│   Tier │ Compute Units │ vCPUs │ RAM (GiB) │ Disk (GiB) │ $ALEPH (Holding) │ + Internet Access   │
│ ╶──────┼───────────────┼───────┼───────────┼────────────┼──────────────────┼───────────────────╴ │
│   1    │ 1             │ 1     │ 2         │ 2          │    200 tokens    │    400 tokens       │
│ ╶──────┼───────────────┼───────┼───────────┼────────────┼──────────────────┼───────────────────╴ │
│   2    │ 2             │ 2     │ 4         │ 4          │    400 tokens    │    800 tokens       │
│ ╶──────┼───────────────┼───────┼───────────┼────────────┼──────────────────┼───────────────────╴ │
│   3    │ 4             │ 4     │ 8         │ 8          │    800 tokens    │    1600 tokens      │
│ ╶──────┼───────────────┼───────┼───────────┼────────────┼──────────────────┼───────────────────╴ │
│   4    │ 6             │ 6     │ 12        │ 12         │   1200 tokens    │    2400 tokens      │
│ ╶──────┼───────────────┼───────┼───────────┼────────────┼──────────────────┼───────────────────╴ │
│   5    │ 8             │ 8     │ 16        │ 16         │   1600 tokens    │    3200 tokens      │
│ ╶──────┼───────────────┼───────┼───────────┼────────────┼──────────────────┼───────────────────╴ │
│   6    │ 12            │ 12    │ 24        │ 24         │   2400 tokens    │    4800 tokens      │
│        ╵               ╵       ╵           ╵            ╵                  ╵                     │
│ Extra Volume Cost: 51.2 token/GiB (Holding) -or- 0.02401 token/GiB/day (Pay-As-You-Go)           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
Select a tier by index: 1
Program name: Feedback API
Ref of runtime? [63f07193e6ee9d207b7d1fcf8286f9aee34e6f12f101d2ec77c1229f92964696] 
Add volume? [y/n] (n): n
Add environment variable? [y/n] (n): n

After your project has been successfully deployed, you will receive a notice that deployed your application, including your API URL, such as:


╭─ Program Created ────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Your program 7067be26978fd4a78fe106a7b428c576195597b7e224f6863bf8f5b57843afa1 has been uploaded on aleph.im.         │
│                                                                                                                      │
│ Available on:                                                                                                        │
│ ↳                                │
│ ↳                                               │
│                                                                                                                      │
│ Visualise on:                                                                                                        │
│  │
│ fe106a7b428c576195597b7e224f6863bf8f5b57843afa1

Congratulations, you have successfully deployed your API to Aleph Cloud 🎉

You can add this API feedback to your DAPP to get user feedback.

Conclusion

The Aleph Cloud does the deployment for developers with CLI and web console.

There is so much you can do with Aleph Cloud, such as:

  1. I -Host your AI models as an example.
  2. I -Host your Frontend Code using Web hosting service.

And more.

You can explore Aleph Doc or join the Aleph Developers community at Discord or Telegram.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button

Adblocker Detected

Please consider supporting us by disabling your ad blocker