Production-ready Rust server template for building HTTP APIs with x402 payment integration on Solana. Accept USDC payments for API access. Includes Axum, Actix and Rocket templates.
x402-solana-rust is an early-stage Rust project in the AI payments / x402 ecosystem, focused on actix-web, api, axum, payments. It currently has 13 GitHub stars and 2 forks, and sits alongside related tools like afara, dna-x402, tdm-integration-kit, tdm-sdk, TDM-Agent-Integration-Kit, solvela.
A production-ready Rust template for building HTTP APIs with x402 payment integration on Solana. Accept USDC payments for API access using the x402 protocol.
This template provides a complete server implementation supporting the x402 payment protocol for Solana. It enables you to create paid API endpoints where users pay with USDC to access protected content.
Key Features:
sequenceDiagram
participant Client
participant Server
participant Facilitator
participant Solana
Client->>Server: GET /api/paid
Server->>Client: 402 Payment Required<br/>{paymentRequirements}
Note over Client: User signs transaction<br/>with wallet
Client->>Server: GET /api/paid<br/>X-PAYMENT: {transaction}
Server->>Facilitator: verify_payment()
Note over Facilitator: Validates transaction
Facilitator->>Server: Valid
Server->>Facilitator: settle_payment()
Facilitator->>Solana: Submit transaction
Solana->>Facilitator: Confirmation
Facilitator->>Server: Settled
Server->>Client: 200 OK<br/>{protected content}
Create a new project with one command:
npx github:crypto-priest/x402-solana-rust my-project
This will:
Copy environment template and add your Solana wallet:
cp .env.example .env
# Edit .env - set RECEIVER_WALLET_ADDRESS
Start the server:
cargo run
Server starts on http://localhost:3000
Web UI (Recommended):
cd frontend
npm install
cp .env.example .env
# Edit .env - add your keypair
npm run dev
cURL:
curl http://localhost:3000/api/health
curl http://localhost:3000/api/free
curl http://localhost:3000/api/paid
| Endpoint | Method | Description | Payment Required |
|---|---|---|---|
/api/health |
GET | Health check and server info | No |
/api/free |
GET | Free access endpoint | No |
/api/paid |
GET | Protected content | Yes (USDC) |
RECEIVER_WALLET_ADDRESS - Your Solana wallet to receive paymentsSOLANA_NETWORK - solana-devnet or solana-mainnet (default: devnet)SOLANA_RPC_URL - RPC endpoint (default: devnet public RPC)USDC_MINT_ADDRESS - USDC token address (default: devnet USDC)DEFAULT_PRICE - Price in micro-USDC (default: 10000 = $0.01)FACILITATOR_URL - Payment processor (default: PayAI community)HOST - Server bind address (default: localhost)PORT - Server port (default: 3000).
├── facilitator/ # Payment facilitator implementations
│ ├── local.rs # Direct blockchain submission locally
│ ├── traits.rs # Facilitator trait
│ └── utils.rs # Common txn utilities
├── frameworks/ # Framework templates
│ ├── axum/ # Axum implementation
│ ├── actix/ # Actix implementation
│ └── rocket/ # Rocket implementation
├── shared/ # Shared code
│ ├── config.rs # Configuration(env)
│ ├── types.rs # x402 types
│ ├── verification.rs # Payment verification functions
│ └── error.rs # Error enum
├── frontend/ # Testing UI
└── init.js # Project generator
verify_payment() functionPaymentResult enumSee framework-specific documentation in frameworks/<framework>/
Use the included frontend testing UI:
Or implement your own client following the x402 protocol specification.
MIT License - see LICENSE file for details
Contributions welcome! Please open an issue or PR.
Built for the Solana ecosystem ♥️
the onramp for pay-as-you-go decentralized storage on IPFS — SOL, USDFC, USDC, and x402 agent payments
DNA — Payment rails for AI agents. x402 micropayment protocol on Solana. Netting, transfer, stream settlement. Receipt anchoring on-chain.
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
Open contract-facing SDK for payable routes and gateway-backed integrations. Thin public surface for authorize, checkout, and session flows.
Developer integration tools for adding TDM payments to AI agents, apps, and workflows. CLI, MCP server, and copy-paste examples
Solana-native AI agent payment infrastructure. AI agents pay for LLM API calls with USDC-SPL on Solana via the x402 protocol.
Agent behavior that compiles
An open SDK for agentic payments. Let AI agents make payments, hold funds, and move money across chains with policy enforcement and human approval built in.
x402 payments in Rust: verify, settle, and monitor payments over HTTP 402 flows
The self-improving LLM router that optimize your agentic workflows with every runs, works with any harnesses, any models, any loops.
Production-ready x402 facilitator server.
Rust SDK for the x402 payment protocol.