Complete x402 (Solana) payment protocol implementation for API monetization. Built for Solana X402 Hackathon.
microapi-hub is an early-stage project in the AI payments / x402 ecosystem. It currently has 0 GitHub stars and 0 forks.
Complete x402 (Solana) payment protocol implementation for API monetization
Built for the Solana X402 Hackathon 🏆
Features • Architecture • Quick Start • Documentation • Contributing
MicroAPI Hub is a complete end-to-end implementation of the x402 payment protocol for Solana, enabling API providers to monetize their endpoints with blockchain payments. This project demonstrates how to build a production-ready payment system that integrates seamlessly with Solana's blockchain.
x402 is an open payment standard that enables clients to pay for external resources (APIs, content, data) using blockchain payments. It follows HTTP status code 402 (Payment Required) semantics and provides a standardized way to implement pay-per-use APIs with on-chain settlement and verifiable receipts.
.well-known/x402 protocol complianceThe following Mermaid diagram shows the end-to-end x402 payment flow across swimlanes for Client, Provider, Facilitator, and Solana:
sequenceDiagram
autonumber
box Client
participant C as Client (Web UI / Agent)
end
box Provider API
participant P as Provider API (x402 Guard)
end
box Facilitator
participant F as Facilitator (Verify & Settle)
end
box Solana
participant S as Solana Network
end
C->>P: 1) GET /api/data (no X-PAYMENT)
P-->>C: 2) 402 Payment Required + PaymentRequirements
note over C: Create x402 Payment Header<br/>- Secure nonce<br/>- Time window<br/>- Authorization payload
C->>P: 3) GET /api/data with X-PAYMENT
P->>F: 4) POST /verify { paymentHeader, requirements }
F-->>P: 5) { isValid: true }
P->>F: 6) POST /settle { paymentHeader, requirements }
F->>S: 7) Submit transaction (native/SPL)
S-->>F: 8) Confirmed (tx hash)
F-->>P: 9) { success: true, txHash }
P-->>C: 10) 200 OK + X-PAYMENT-RESPONSE (txHash)
Alternatively, here is a swimlane-style activity view using Mermaid flowchart subgraphs (lanes):
flowchart LR
subgraph L1[Client]
A[Request /api/data] --> B[Receive 402 + Requirements]
B --> C[Create X-PAYMENT header]
C --> D[Call /api/data with header]
end
subgraph L2[Provider]
D --> E[Verify with Facilitator]
E --> G[Settle with Facilitator]
G --> H[Return 200 + X-PAYMENT-RESPONSE]
end
subgraph L3[Facilitator]
E --> F[Verify Authorization]
G --> I[Build & Submit Transaction]
end
subgraph L4[Solana]
I --> J[Confirm Transaction]
end
J --> H
┌─────────┐ ┌──────────┐ ┌─────────────┐ ┌──────────┐
│ Client │ │ Provider │ │ Facilitator │ │ Solana │
└────┬────┘ └────┬─────┘ └──────┬──────┘ └────┬─────┘
│ │ │ │
│ 1. GET /api/data │ │ │
├──────────────────►│ │ │
│ │ │ │
│ 2. 402 Payment │ │ │
│ Required │ │ │
│ + Requirements │ │ │
│◄──────────────────┤ │ │
│ │ │ │
│ 3. Create Payment │ │ │
│ Authorization │ │ │
│ (with nonce) │ │ │
│ │ │ │
│ 4. POST /api/data │ │ │
│ + X-PAYMENT │ │ │
│ header │ │ │
├──────────────────►│ │ │
│ │ │ │
│ │ 5. POST /verify │ │
│ ├──────────────────────►│ │
│ │ │ │
│ │ 6. Verify Response │ │
│ │ {isValid: true} │ │
│ │◄──────────────────────┤ │
│ │ │ │
│ │ 7. POST /settle │ │
│ ├──────────────────────►│ │
│ │ │ │
│ │ │ 8. Create Transaction│
│ │ ├─────────────────────►│
│ │ │ │
│ │ │ 9. Transaction Hash │
│ │ │◄─────────────────────┤
│ │ │ │
│ │ 10. Settlement Resp │ │
│ │ {success: true, │ │
│ │ txHash: "..."} │ │
│ │◄──────────────────────┤ │
│ │ │ │
│ 11. 200 OK │ │ │
│ + X-PAYMENT- │ │ │
│ RESPONSE │ │ │
│◄──────────────────┤ │ │
│ │ │ │
┌─────────────────────────────────────────────────────────────┐
│ Web UI (Next.js) │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ Wallet │ │ Payment │ │ Resource │ │
│ │ Provider │ │ Modal │ │ Card │ │
│ │ │ │ │ │ │ │
│ │ • Connect │ │ • Show │ │ • Display │ │
│ │ • Sign │ │ Amount │ │ Info │ │
│ │ • State │ │ • Execute │ │ • Trigger │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
│
│ HTTP
▼
┌─────────────────────────────────────────────────────────────┐
│ Provider API Service │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌────────────────────────────────────────────────────┐ │
│ │ x402 Guard Middleware │ │
│ │ │ │
│ │ 1. Check X-PAYMENT header │ │
│ │ 2. If missing → Return 402 │ │
│ │ 3. If present → Verify with Facilitator │ │
│ │ 4. If valid → Settle with Facilitator │ │
│ │ 5. If settled → Allow request to proceed │ │
│ └────────────────────────────────────────────────────┘ │
│ │ │
│ │ POST /verify, /settle │
│ ▼ │
└─────────────────────────────────────────────────────────────┘
│
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Facilitator Service │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌────────────────────────────────────────────────────┐ │
│ │ Verification Engine │ │
│ │ │ │
│ │ • Parse payment header │ │
│ │ • Validate signature │ │
│ │ • Check nonce (replay protection) │ │
│ │ • Validate time window │ │
│ │ • Verify amount & recipient │ │
│ └────────────────────────────────────────────────────┘ │
│ │ │
│ ┌────────────────────────────────────────────────────┐ │
│ │ Settlement Engine │ │
│ │ │ │
│ │ • Create Solana transaction │ │
│ │ • Sign with fee payer │ │
│ │ • Submit to blockchain │ │
│ │ • Wait for confirmation │ │
│ │ • Return transaction hash │ │
│ └────────────────────────────────────────────────────┘ │
│ │ │
│ │ RPC │
│ ▼ │
└─────────────────────────────────────────────────────────────┘
│
│
▼
┌──────────────┐
│ Solana │
│ Blockchain │
└──────────────┘
# Clone the repository
git clone https://github.com/yourusername/microapi-hub.git
cd microapi-hub
# Install dependencies
npm install --workspaces
cd services/facilitator
# Create .env file
cat > .env << EOF
PORT=8787
NETWORK=devnet
RPC_URL=https://api.devnet.solana.com
FEE_PAYER_SECRET= # Optional: base58-encoded keypair
SETTLEMENT_MODE=native
DEMO_MODE=true
EOF
# Start facilitator
npm run dev
cd services/provider-api
# Create .env file
cat > .env << EOF
PORT=8080
PAY_TO_PUBKEY=YOUR_SOLANA_PUBKEY
USDC_MINT=EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v
FACILITATOR_URL=http://localhost:8787
EOF
# Start provider API
npm run dev
cd clients/web
# Create .env.local file
cat > .env.local << EOF
NEXT_PUBLIC_PROVIDER_DISCOVERY_URL=http://localhost:8080/.well-known/x402
EOF
# Start web UI
npm run dev
Payment verification and on-chain settlement service.
Endpoints:
POST /verify - Verify payment authorizationPOST /settle - Settle payment on-chainGET /health - Health checkGET /supported - Supported payment schemesKey Features:
API server with x402 payment protection.
Endpoints:
GET /api/data - Protected endpoint (example)GET /.well-known/x402 - Discovery endpointGET /health - Health checkKey Features:
Next.js application with wallet integration.
Features:
microapi-hub/
├── services/
│ ├── facilitator/ # Payment verification & settlement
│ │ ├── src/
│ │ │ ├── index.ts # Main facilitator service
│ │ │ ├── config.ts # Configuration management
│ │ │ ├── errors.ts # Error handling
│ │ │ └── registry.ts # Registry client
│ │ └── package.json
│ └── provider-api/ # Protected API server
│ ├── src/
│ │ ├── index.ts # Main provider service
│ │ └── config.ts # Configuration
│ └── package.json
├── clients/
│ ├── web/ # Next.js web UI
│ │ ├── app/ # Next.js app router
│ │ ├── components/ # React components
│ │ ├── lib/ # Utilities
│ │ └── package.json
│ └── agent-demo/ # Example client
├── contracts/
│ └── registry/ # Solana Anchor program
│ └── programs/
│ └── registry/
│ └── src/
│ └── lib.rs # Registry contract
├── shared/
│ └── types/ # Shared TypeScript types
│ ├── x402.ts # x402 protocol types
│ ├── errors.ts # Error types
│ └── registry.ts # Registry types
├── docs/ # Documentation
│ ├── API.md
│ └── DEVELOPER.md
├── infra/ # Infrastructure
│ └── docker-compose.yml
└── x402/ # x402 protocol library
# Run all tests
npm test
# Run E2E tests
npm run e2e
# Build all services
npm run build
# Start all services with Docker Compose
cd infra
docker-compose up
✅ x402 Protocol Integration: Full specification implementation
✅ Solana Integration: Deployed to devnet, mainnet-ready
✅ Open Source: All code on GitHub
✅ Demo Video: 3-minute demonstration
✅ Documentation: Comprehensive setup and usage guides
See HACKATHON.md for demo video script and submission details.
Contributions are welcome! Please feel free to submit a Pull Request.
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)This project is open source. See LICENSE file for details.
/docs directoryBuilt with ❤️ for the Solana X402 Hackathon
Your AI trading terminal assistant for US stocks, commodities, forex, and crypto.
The agent-native LLM router for autonomous agents. 55+ models (8 free), <1ms local routing, USDC payments on Base & Solana via x402.
A payments protocol for the internet. Built on HTTP.
A local-first AI agent with persistent memory, emotional intelligence, and a peer-to-peer skills economy.
The trust layer for agent-to-agent commerce — natural-language mandates, ERC-7710 delegated permissions, x402 payments, escrow, and dispute resolution as one open, catch-all Agent Skill / Claude Code plugin.
The AI agent with a wallet — spends USDC autonomously to get real work done. Apache-2.0, TypeScript.