Skip to content

A Rust-based HTTP server exposing Solana-related endpoints for keypair generation, SPL token operations, message signing/verification, and transaction instruction creation.

Notifications You must be signed in to change notification settings

br8bit/rust-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solana HTTP Server

A Rust-based HTTP server exposing Solana-related endpoints for keypair generation, SPL token operations, message signing/verification, and transaction instruction creation.

Features

  • Generate Solana keypairs
  • Create SPL token mint instructions
  • Create SPL token mint-to instructions
  • Sign and verify messages using Ed25519
  • Create SOL transfer instructions
  • Create SPL token transfer instructions

Running the Server

cargo run

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

API Endpoints

All endpoints return JSON responses with the following format:

Success Response (Status 200)

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

Error Response (Status 400)

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

Endpoints

1. Generate Keypair

POST /keypair

Generates a new Solana keypair.

Response:

{
  "success": true,
  "data": {
    "pubkey": "base58-encoded-public-key",
    "secret": "base58-encoded-secret-key"
  }
}

2. Create Token

POST /token/create

Creates a new SPL token initialize mint instruction.

Request:

{
  "mintAuthority": "base58-encoded-public-key",
  "mint": "base58-encoded-public-key",
  "decimals": 6
}

Response:

{
  "success": true,
  "data": {
    "program_id": "string",
    "accounts": [
      {
        "pubkey": "pubkey", 
        "is_signer": false, 
        "is_writable": true
      }
    ],
    "instruction_data": "base64-encoded-data"
  }
}

3. Mint Token

POST /token/mint

Creates a mint-to instruction for SPL tokens.

Request:

{
  "mint": "mint-address",
  "destination": "destination-user-address",
  "authority": "authority-address",
  "amount": 1000000
}

Response:

{
  "success": true,
  "data": {
    "program_id": "string",
    "accounts": [
      {
        "pubkey": "pubkey",
        "is_signer": false,
        "is_writable": true
      }
    ],
    "instruction_data": "base64-encoded-data"
  }
}

4. Sign Message

POST /message/sign

Signs a message using a private key.

Request:

{
  "message": "Hello, Solana!",
  "secret": "base58-encoded-secret-key"
}

Response:

{
  "success": true,
  "data": {
    "signature": "base64-encoded-signature",
    "public_key": "base58-encoded-public-key",
    "message": "Hello, Solana!"
  }
}

5. Verify Message

POST /message/verify

Verifies a signed message.

Request:

{
  "message": "Hello, Solana!",
  "signature": "base64-encoded-signature",
  "pubkey": "base58-encoded-public-key"
}

Response:

{
  "success": true,
  "data": {
    "valid": true,
    "message": "Hello, Solana!",
    "pubkey": "base58-encoded-public-key"
  }
}

6. Send SOL

POST /send/sol

Creates a SOL transfer instruction.

Request:

{
  "from": "sender-address",
  "to": "recipient-address",
  "lamports": 100000
}

Response:

{
  "success": true,
  "data": {
    "program_id": "system-program-id",
    "accounts": [
      "address-of-first-account",
      "address-of-second-account"
    ],
    "instruction_data": "base64-encoded-instruction-data"
  }
}

7. Send Token

POST /send/token

Creates an SPL token transfer instruction.

Request:

{
  "destination": "destination-user-address",
  "mint": "mint-address",
  "owner": "owner-address",
  "amount": 100000
}

Response:

{
  "success": true,
  "data": {
    "program_id": "token-program-id",
    "accounts": [
      {
        "pubkey": "pubkey", 
        "isSigner": false
      }
    ],
    "instruction_data": "base64-encoded-instruction-data"
  }
}

Technical Details

  • Uses Ed25519 for signing/verification
  • Base58 encoding for public/private keys
  • Base64 encoding for signatures and instruction data
  • All endpoints include proper input validation
  • CORS enabled for cross-origin requests

Dependencies

  • tokio - Async runtime
  • axum - Web framework
  • serde - Serialization
  • solana-sdk - Solana functionality
  • spl-token - SPL token operations
  • bs58 - Base58 encoding
  • base64 - Base64 encoding
  • tower-http - HTTP middleware

About

A Rust-based HTTP server exposing Solana-related endpoints for keypair generation, SPL token operations, message signing/verification, and transaction instruction creation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published