This project demonstrates how to use X402 payment system with Express.js, allowing API endpoints to charge for access using Solana USDC payments.
src/index.ts): Express.js server with X402-protected API routessrc/client.ts): Example client that automatically pays when calling protected endpointssrc/routes/index.ts): API routes with X402 payment middlewaresrc/config.ts): Centralized configuration for payment settings (network, asset, amount, payment address)The /api/protected endpoint requires a payment of 100 USDC to access. It uses X402 middleware to automatically verify and process payments.
Payment configuration is centralized in src/config.ts. The following environment variables can be set to customize the payment settings:
PAY_TO_ADDRESS: Solana address to receive payments (defaults to a test address)NETWORK: Solana network (defaults to "mainnet-beta")ASSET: Token asset to use for payments (defaults to "USDC")AMOUNT: Payment amount per request (defaults to "100")The client demonstrates how to automatically pay for API access using X402:
fetch to automatically handle paymentsX402 middleware is configured using centralized settings in src/config.ts:
NETWORK env var)ASSET env var)AMOUNT env var)PAY_TO_ADDRESS env varhttps://facilitator.corbits.ioThe middleware automatically:
For detailed setup instructions, deployment guides, and code examples, please refer to the GitHub repository README.