Express.js
Install
@x402/svm:
Minimal example (EVM)
Minimal example (Solana)
Configuration
ThepaymentMiddleware takes a route map and a resource server:
"METHOD /path" to payment requirements:
eip155:8453— Base mainneteip155:84532— Base Sepolia (testnet)solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp— Solana mainnetsolana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1— Solana Devnet
Facilitator URL
| Environment | URL |
|---|---|
| Sandbox (free, testnet) | https://x402.renvoy.ai/sandbox |
| Production (API key) | https://x402.renvoy.ai/v1/YOUR_API_KEY |
Any framework
If you’re not using Express, you can implement the 402 flow directly. The protocol is framework-agnostic.What your server does
- Check for payment: Look for the
X-PAYMENTheader on incoming requests - No payment? Return
402with payment requirements in the response body - Has payment? Forward it to the facilitator’s
/settleendpoint for on-chain settlement - Settlement succeeds? Return the requested resource
402 response format
When a request arrives without payment, respond with:maxAmountRequired is in USDC atomic units (6 decimals). "100000" = 0.10 USDC.
Settle request
Forward the client’sX-PAYMENT header to the facilitator: