A collection of minimal x402 (HTTP 402 Payment Required) implementations using Solana blockchain.
x402 is an open payments standard that integrates micropayments directly into HTTP using the 402 "Payment Required" status code. These examples show how to implement x402 with Solana blockchain for payment verification.
There are 3 examples in this project:
- Pay in SOL
- Pay in USDC
- Pay with Coinbase Facilitator
Each example has its own README with detailed instructions on how to run the example.
From the project root:
Basic x402 implementation using native SOL tokens.
Features:
- Client signs, server submits transactions
- 3-step verification: Introspect → Simulate → Submit
- Blockchain-native replay protection
- Minimal payload (just serialized transaction)
Quick Start:
# Terminal 1: Start server
npm run sol:server
# Terminal 2: Run client
npm run sol:clientx402 implementation using USDC (SPL Token) on devnet.
Features:
- SPL Token transfer verification
- USD-denominated pricing (0.01 USDC)
- Automatic token account creation
- Decimal handling (6 decimals)
Quick Start:
# Terminal 1: Start server
npm run usdc:server
# Terminal 2: Run client (requires devnet USDC)
npm run usdc:clientx402 implementation using Coinbase's official libraries and facilitator service.
Features:
- Gasless payments - Users don't need SOL for fees (Until they maybe run out of funds)
- Official
x402-expressandx402-axioslibraries - Production-ready infrastructure
- Automatic transaction handling
- Minimal code (~50 lines per side)
Quick Start:
# Terminal 1: Start server
npm run coinbase:server
# Terminal 2: Run client (requires devnet USDC)
npm run coinbase:clientx402 implementation using Solana Actions (Blinks).
Features:
- QR code payments
- Mobile wallet support
- Deep linking
- Client requests a resource
- Server responds with
402 Payment Requiredand payment details - Client creates and signs a transaction (doesn't submit it)
- Client sends the signed transaction in
X-Paymentheader - Server verifies and submits the transaction to blockchain
- Server confirms payment and grants access to the resource
- ⚡ Fast: Sub-second finality
- 💰 Cheap: Fractions of a cent per transaction
- 🔒 Secure: Built-in replay protection
- 🌍 Global: Permissionless and borderless
402-minimal/
├── README.md # This file
├── package.json # Shared dependencies
├── tsconfig.json # TypeScript config
│
├── pay-in-sol/ # Native SOL payments
│ ├── README.md
│ ├── server.ts
│ ├── client.ts
│ └── client.json
│
├── pay-in-usdc/ # SPL Token (USDC) payments
│ ├── README.md
│ ├── server.ts
│ ├── client.ts
│ └── client.json
│
├── pay-using-coinbase/ # Coinbase facilitator integration
│ ├── README.md
│ ├── x402-demo-server.ts
│ ├── x402-demo-client.ts
│ └── client.json
│
└── pay-with-blinks/ # Blinks example (coming soon)
└── ...
- Node.js 18+
- Solana CLI (for devnet testing)
- Basic understanding of Solana transactions
Each example is self-contained with its own README and can be run independently using npm scripts:
# SOL payments
npm run sol:server # Start SOL payment server
npm run sol:client # Run SOL payment client
# USDC payments
npm run usdc:server # Start USDC payment server
npm run usdc:client # Run USDC payment client
# Coinbase facilitator
npm run coinbase:server # Start Coinbase x402 server
npm run coinbase:client # Run Coinbase x402 clientContributions are welcome! Please feel free to submit a Pull Request.
MIT
Built with ❤️ for the Solana ecosystem