Build Payment Apps
in Minutes, Not Weeks.
Micropay is a high-performance Solana SDK for implementing friction-free x402 protocol payments. Secure, stateless, and built for the future.
Stateless Auth
Secure x402 error handling using cryptographic signatures.
SOL & SPL Tokens
Native support for any SPL token via Jupiter integration.
AI Optimized
Designed for autonomous agents with local keypair support.
Why x402?
Micropayments,
Architected for Velocity.
Traditional payments are too slow for the AI era. x402 provides a standardized human-and-machine-readable bridge for value transfer.
Standardization
Native HTTP 402 error handling.
AI Integration
Secure agent-to-agent keypair support.
Live Demos
Content Paywall
Unlock premium reading experiences with sub-second wallet signatures.
Autonomous Payments
Watch specialists negotiate and pay via cryptographically verified links.
Features Demonstrated
Protocol
- x402 Implementation
- SOL & SPL Tokens
- Stateless Sessions
Automation
- AI Agent Wallets
- PayAI Formats
- Priority Fees
Reliability
- On-Chain Verification
- RPC Fallback
- Replay Protection
Installation
Get started in seconds with npm or yarn.
1 Install the package
2 Set up environment variables
Pro Tip
Use Devnet for testing. Get free SOL from the Solana Faucet.
Quick Start
Protect your API routes with x402 middleware in just a few lines of code.
Next.js App Router
Protect API routes with middleware
Express.js
Add middleware to any route
React Client
Connect wallet and make payments
โจThat's it!
You now have a fully functional micropayment system. The middleware handles:
Deployment
Deploy Your Own Facilitator
For production, spin up a high-performance verification node in seconds. Zero config files to editโjust bring your RPC URL.
2Configuration Workflow
Initiate Deployment
Select your preferred cloud provider above. You'll be redirected to their setup wizard.
Configure Environment Variables
โ ๏ธ Important: Default is Devnet!
The facilitator deploys with devnet by default. For mainnet production, you must change the environment variables after deployment.
Default: https://api.devnet.solana.com
Verify & Connect
Once deployed, verify your node is active with the health check.
GET /healthGET /metricsDeployment FAQ
What happens when I click Deploy?
The platform (Railway/Heroku/Render) will automatically fork this open-source repository into your own account. It will then pause to ask for your Environment Variables before building the Go binaries.
Can I change networks later?
Yes. Simply go to your project dashboard's "Variables" or "Settings" tab and update SOLANA_NETWORK to mainnet-beta or devnet.
How It Works
01Lifecycle of a Payment
Request
Client hits a protected endpoint.
Challenge
Server returns 402 + payment URL.
Payment
Wallet signs and sends SOL.
Unlock
Server verifies and issues session.
Protocol Architecture
Client
Browser / Agent
Middleware
Next.js / Bun
Solana
Mainnet / Devnet
Wallet Topology
Consumer to API
Standard paywall flow for web users.
Payer
User Wallet
Receiver
CREATOR_WALLET
Agent to Agent
Autonomous machine payments.
Payer
Agent Wallet
Receiver
CREATOR_WALLET
Configuration Checklist
Consumer Setup
- CREATOR_WALLET_ADDRESS is set
- RPC_URL is reachable
- Devnet SOL in user wallet
Agent Setup
- AGENT_KEYPAIR_SECRET is set
- Fund agent wallet with SOL
- Configure agent fee tier
AI Agent Payments
Machines playing
by human rules.
x402 allows AI agents to negotiate and fulfill payments autonomously. By using standard HTTP error 402, agents can identify payment requirements and resolve them using their own keypairs.
Detect 402 Challenge
Agent receives 402 Payment Required with metadata.
Sign & Authorize
Agent signs tx with AGENT_KEYPAIR_SECRET.
Validation
Resource server validates the on-chain signature.
Technical Implementation
Autonomous Wallets
Agents manage their own SOL balances for pay-per-request.
Cloud Integration
Deploy agents on Vercel AI SDK or similar stacks.
Usage Metrics
Track spending and efficiency per agent session.
Give Your Agents
Financial Autonomy.
The createPayingAgent helper is the sexiest way to equip your AI with a wallet. It handles balance checks, x402 negotiation, and transaction signing automatically.
Integration Guide
Instead of manually constructing transactions, your agent simply "fetches" URLs. If the URL is behind a paywall (402 Payment Required), the agent automatically negotiates the price, signs the transaction, and retries the request with the payment proof attached.
How it Works: The Client-Server Handshake
It takes two to tango using the x402 protocol. Your agent is the Client, but the URL it fetches must be a x402-enabled Server.
Must throw 402 Payment Required when unpaid.
Catches the 402, pays on-chain, and retries.
GET /premium
> Authorization: X402 ...
0Prerequisite: Protect your API (Next.js)
Currently, we provide a plug-and-play middleware for Next.js App Router.
Authorization: X402 ... header and verifying the signature.1Basic Usage
2Checking Balance
3Advanced Configuration
Protect your agent from draining its wallet on malicious sites.
fetch-compatible interface. You can pass agent.fetch directly to any library that accepts a custom fetcher (like OpenAI, LangChain, or Eliza) to seamlessly enable payments within those frameworks.PayAI Format
The Universal Standard.
Native support for the PayAI payment format - a universal protocol that enables cross-chain payment discovery. Micropay automatically detects and transforms PayAI payloads into x402 compliant authorizations.
PayAI Payload Structure
Protocol Note
The exact-svm scheme ensures sub-second verification by matching transactions directly.
Network Mapping
solana
solana:5eykt...pY1vz
solana-devnet
solana:EtWTR...U2xqa
base
eip155:8453
Cross-Chain Discovery
Enable users to pay on one chain and unlock on another. Micropay handles bridging confirmation automatically.
Payment Request
402 response includes PayAI bridge link.
Verification
Oracle network confirms cross-chain state.
Settlement
Resource server issues localized session.
Verification Modes
Choose Your Trust Model.
Micropay supports three distinct trust topologies. Default to the managed PayAI Network, run your own Private Facilitator, or go fully Self-Sovereign with direct RPC verification.
Hosted (PayAI)
- Zero Setup
- Global Cache
- Managed Reliability
Private (Railway)
- Your Infrastructure
- Custom Logic
- Private Logs
Sovereign (RPC)
- Trustless
- Direct Blockchain
- Maximum Control
Signature Registry
Micropay uses an internal registry to track and verify on-chain signatures. This prevents replay attacks and ensures each payment is only used once.
Deterministic
Signatures are hashed and stored for lookup.
High Performance
LRU caching for sub-millisecond lookups.
Facilitator API Format
The custom facilitator accepts a standard x402 verification payload. You can use this to integrate payment verification into any backend.
Installation
Start Building Today.
Configuration
Tweak the resource server to match your security and performance needs.
Resource Server Options
Quick Start
The 1-Minute Protection.
Protect any API route with just a few lines of code. Micropay handles the 402 response, verification, and session persistence.
Middleware
Express.js
For Node backends
Next.js
For App Router
The Execution Flow
Interception
Middleware catches request & checks for Authorization header.
Validation
On-chain verification or PayAI facilitator check.
Persistence
Verified session is stored in an HTTP-only cookie.
Grant
Downstream handler receives the verified payer object.
Security
Replay Protection
Every transaction signature is registered and can only be used once per session. This prevents malicious actors from "replaying" a valid payment to unlock multiple resources.
Stateless Verification
By using Solana as the source of truth, the middleware doesn't need to maintain a database of users. If the on-chain data matches the request, access is granted.
Agent Demo Configuration
To enable the **Agent-to-Agent** payment demo using your own infrastructure:
Deploy Facilitator
Deploy your facilitator to Railway/Heroku using the One-Click button above.
Get Service URL
On Railway: Click your project โ Click the Service โ Copy the Public Networking URL (e.g. https://my-app.up.railway.app).
Set Environment Variable
Add this to your local or deployed demo environment:
Verification Architecture
This demo implements a "Split Architecture" (Toly Design) to optimize for both trust and convenience:
Standard Flow
Agent โ API payments use the managed PayAI Network. Zero-config, high availability for standard SaaS interactions.
Sovereign Flow
Agent โ Agent payments use your Custom Railway Node. Demonstrates true p2p sovereignty and private infrastructure verification.
Priority Fees Support
Under high network congestion, Micropay supports Compute Budget instructions to ensure your payment transactions land on-chain without delay.
Troubleshooting
Network Error: Fetch Failed
Node 18+ resolves localhost to IPv6 (::1). Use http://127.0.0.1:3000 instead of localhost in your APP_URL.
Payment Not Verifying
Check CREATOR_WALLET_ADDRESS and lamport decimals. Use a better RPC provider if hits rate limits.
Session Expired
Increase SESSION_DURATION_HOURS or ensure SESSION_SECRET is stable across deployments.
Common Error Codes
402 Payment RequiredResource protected by x402. Payer must provide auth header.403 ForbiddenInvalid session or verified payment does not match price.503 Service UnavailableRPC node failed or facilitator is offline.Pricing
Free & Open Source
Micropay is MIT licensed and free to use. Zero platform fees, zero middleman. You keep 100% of your earnings.
Roadmap
Core Protocol
Initial x402 implementation with SVM support.
SPL Standard
Native support for USDC and major SPL tokens.
EVM Briding
Expanding the x402 standard to Base and Arbitrum.
API Reference
executeAgentPaymentgetAgentBalancex402MiddlewareExpressAdaptercreateX402MiddlewaregetSolPriceusdToLamportsSupport Dev.
Micropay is open source. If you find it useful, consider supporting core development with a small donation.
7fPjNJaEHtepp1ZRr6GsaW1k22U1FupQtwuHUkTb6Xg9