Solana USDC Demo
The Solana demo shows how to implement HTTP 402 paywalls on Solana blockchain using the Faremeter middleware with Crossmint smart wallet integration. This demonstrates cross-chain compatibility of the x402 payment protocol.Overview
This demo implements a payment-protected endpoint on Solana, supporting both:- Crossmint API Signer: Server-side signing with Crossmint smart wallets
- Crossmint Delegated Wallet: External private key signer to Crossmint smart wallet
- Solana blockchain payment settlement
- USDC SPL token payments
- Faremeter middleware for Solana x402 support
- Crossmint wallet integration for Solana
- Protected
/protectedendpoint requiring 0.01 USDC - Supports both devnet and mainnet-beta
Prerequisites
Development Tools
- Node.js 18+
- Solana CLI tools (for keypair generation)
- npm
Crossmint Account
- Create account at https://www.crossmint.com/
- Generate Server API Key (
sk_staging_...) - Configure for Solana network support
Testnet Tokens (Devnet)
SOL for transaction fees:- Visit: https://faucet.solana.com
- Paste your Solana address
- Request SOL
- Visit: https://faucet.circle.com/
- Select “Solana Devnet”
- Request USDC
Setup
Method 1: Crossmint API Signer
1. Generate Keypairs
2. Configure Environment
Create.env file:
.env
PAYTO_KEYPAIR_PATH- Recipient wallet keypair filePAYER_KEYPAIR_PATH- Payer wallet keypair fileNETWORK- Solana cluster (devnet or mainnet-beta)CROSSMINT_API_KEY- Your Crossmint server API keyPORT- Server listen portRPC_URL- Solana RPC endpointFACILITATOR_URL- Faremeter facilitator endpoint
3. Fund Accounts
Get the public keys:4. Install and Build
5. Start Server
6. Run Test Script
- Attempts to access
/protectedwithout payment (gets 402) - Creates payment authorization
- Retries with X-PAYMENT header
- Receives success response
Method 2: Crossmint Delegated Wallet
Delegated wallets use an external private key as admin signer for a Crossmint smart wallet.1. Generate Payer Keypair
2. Fund Payer
Ensure the payer has SOL and USDC on Solana devnet.3. Create Delegated Wallet
.env:
4. Check Wallet Configuration
- Wallet exists
- Admin signer is configured
- Balances (SOL and USDC)
5. Start Facilitator (Terminal 1)
Clone and run Faremeter locally:6. Start Server (Terminal 2)
7. Run Delegated Wallet Test (Terminal 3)
Server Implementation
The server uses Faremeter middleware for Solana x402 support:src/server.ts
Payment Configuration
Thex402Exact function creates payment requirements:
Alternative: Native SOL Payments
You can also accept native SOL:Usage
Request Without Payment
Request With Payment
Generate and include payment authorization:Crossmint Wallet Integration
API Signer
Server-side signing with Crossmint:Delegated Wallet
External signer for Crossmint smart wallet:Faremeter Facilitator
Faremeter provides Solana-specific x402 middleware and facilitator services.Running Facilitator Locally
http://localhost:4000 by default.
Using Hosted Facilitator
For testing, use the public facilitator:Payment Flow
Network Configuration
Devnet (Testing)
- SOL: https://faucet.solana.com
- USDC: https://faucet.circle.com/ (select Solana Devnet)
Mainnet (Production)
- Purchase SOL from exchanges
- Swap for USDC on Solana DEXs (Jupiter, Raydium)
Dependencies
package.json
Key Differences from EVM
| Feature | EVM (Ethereum/Base) | Solana |
|---|---|---|
| Middleware | x402-express | @faremeter/middleware |
| Signature Type | EIP-712 typed data | Solana transaction |
| Token Standard | ERC-20 | SPL Token |
| Payment Asset | USDC (ERC-20) | USDC (SPL) |
| Decimals | 6 (USDC) | 6 (USDC), 9 (SOL) |
| Account Model | Smart contracts | Program accounts |
| Facilitator | Coinbase x402 | Faremeter |
Next Steps
Ping Demo
Start with basic EVM implementation
Ping Crossmint
Learn Crossmint EVM integration
Faremeter Docs
Deep dive into Faremeter middleware
Solana Docs
Learn Solana development
Troubleshooting
Keypair Generation Fails
Error:solana-keygen: command not found
Solution: Install Solana CLI tools:
Insufficient Funds
Error: Transaction fails with “insufficient funds” Solution:- Ensure payer has SOL for transaction fees (~0.001 SOL per transaction)
- Ensure payer has USDC for payment amount (0.01 USDC for this demo)
- Check balances:
solana balance <address>
RPC Connection Failed
Error: Cannot connect to Solana RPC Solution:- Verify RPC_URL is correct for your network
- Use Alchemy/QuickNode for reliable RPC access
- Check network status: https://status.solana.com
Facilitator Unreachable
Error: Cannot connect to facilitator Solution:- Verify FACILITATOR_URL is accessible
- If using local facilitator, ensure it’s running
- Check firewall/network settings
- Try public facilitator:
https://facilitator.corbits.dev
Crossmint Wallet Creation Fails
Error: Invalid API key or wallet creation failed Solution:- Verify API key format (
sk_staging_...) - Ensure Crossmint account has Solana enabled
- Check network parameter matches (devnet vs mainnet)
- Review Crossmint dashboard for account status