Skip to content

Latest commit

 

History

History
180 lines (135 loc) · 3.61 KB

File metadata and controls

180 lines (135 loc) · 3.61 KB

Solana Blockchain Server

A Rust-based HTTP server that provides Solana blockchain operations including keypair generation, token operations, message signing/verification, and SOL/token transfers.

Features

  • Generate Solana keypairs
  • Create and mint SPL tokens
  • Sign and verify messages using Ed25519
  • Send SOL and SPL token transfers
  • Input validation and error handling
  • CORS enabled for web applications

Project Structure

src/main.rs – Currently contains the application entry point, server startup, and all other logic that should be moved into separate modules.

Quick Start

Prerequisites

  • Rust (latest stable version)
  • Cargo package manager

Installation

  1. Clone the repository:
git clone <your-repo-url>
cd solana-http-server
  1. Build the project:
cargo build --release
  1. Run the server:
cargo run --release

The server will start on http://localhost:3000

API Endpoints

Health Check

  • GET / - Check if server is running

Keypair Generation

  • POST /keypair - Generate a new Solana keypair

Token Operations

  • POST /token/create - Create a new SPL token mint instruction
  • POST /token/mint - Create a mint-to instruction for SPL tokens

Message Operations

  • POST /message/sign - Sign a message using a private key
  • POST /message/verify - Verify a signed message

Transfer Operations

  • POST /send/sol - Create a SOL transfer instruction
  • POST /send/token - Create an SPL token transfer instruction

Example Usage

Generate Keypair

curl -X POST http://localhost:3000/keypair

Sign Message

curl -X POST http://localhost:3000/message/sign \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Hello, Solana!",
    "secret": "your-base58-encoded-secret-key"
  }'

Create Token

curl -X POST http://localhost:3000/token/create \
  -H "Content-Type: application/json" \
  -d '{
    "mint_authority": "your-mint-authority-pubkey",
    "mint": "your-mint-pubkey",
    "decimals": 6
  }'

Deployment with ngrok

1. Install ngrok

# Download ngrok
wget https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz
tar xvzf ngrok-v3-stable-linux-amd64.tgz

# Or use snap
sudo snap install ngrok

2. Start the Rust server

cargo run --release

3. In another terminal, start ngrok

ngrok http 3000

4. Use the ngrok URL

ngrok will provide you with a public URL like https://abc123.ngrok.io that you can use to access your server from anywhere.

Response Format

All endpoints return JSON responses in the following format:

Success Response (Status 200)

{
  "success": true,
  "data": { /* endpoint-specific result */ }
}

Error Response (Status 400)

{
  "success": false,
  "error": "Description of error"
}

Security Considerations

  • No private keys are stored on the server
  • All cryptographic operations use standard libraries
  • Input validation for all endpoints
  • Proper error handling to avoid information leakage
  • CORS is enabled for web application integration

Development

Running in Development Mode

cargo run

Running Tests

cargo test

Testing the Server

./test_server.sh

Building for Production

cargo build --release

Dependencies

  • axum - Web framework

  • tokio - Async runtime

  • solana-sdk - Solana SDK for blockchain operations

  • spl-token - SPL token program integration

  • serde - Serialization/deserialization

  • tower-http - HTTP middleware (CORS)

License

MIT License