x402 Payments
Gate any HTTP endpoint behind a stablecoin payment. Payers sign off-chain — no gas fees on EVM, no pre-approval required. Your server middleware handles verification and settlement in one call.
Works on Base, Solana, and Radius today. Use the hosted facilitator at x402.stablecoin.xyz — no infrastructure to run.
npm install @stablecoin.xyz/x402How it works
Server — add one middleware call to gate your endpoint:
import { x402Middleware } from '@stablecoin.xyz/x402/middleware/express'
app.get('/premium', x402Middleware({
payTo: '0xYourAddress',
amount: '1000000000000000', // 0.001 SBC
network: 'base',
apiKey: process.env.API_KEY,
}), handler)Client — client.fetch is a drop-in for fetch. It handles the 402, signs the payment, and retries automatically:
import { createX402Client, viemSignerAdapter } from '@stablecoin.xyz/x402/evm'
const client = createX402Client({ signer: viemSignerAdapter(walletClient), network: 'base' })
const res = await client.fetch('https://api.example.com/premium')The payment flow:
Client Your Server x402.stablecoin.xyz
│ │ │
├──── GET /premium ──────────►│ │
│◄─── 402 + payment terms ────┤ │
│ │ │
│ (signs off-chain, no gas) │ │
│ │ │
├──── GET /premium ──────────►│ │
│ + PAYMENT-SIGNATURE ├──── verify + settle ─────►│
│ │◄─── tx confirmed ─────────┤
│◄─── 200 + your data ────────┤ │The facilitator executes the on-chain transfer. Your route handler only runs after payment is confirmed.
Networks
type NetworkKey =
| 'base' // Base mainnet — 18 decimals
| 'base-sepolia' // Base Sepolia — 6 decimals (testnet, free)
| 'radius' // Radius mainnet — 6 decimals
| 'radius-testnet' // Radius testnet — 6 decimals (testnet, free)
| 'solana' // Solana mainnet — 9 decimals
| 'solana-devnet' // Solana Devnet — 9 decimals (testnet, free)| Network | Key | Decimals | Status |
|---|---|---|---|
| Base | base | 18 | Mainnet |
| Base Sepolia | base-sepolia | 6 | Testnet (free) |
| Radius | radius | 6 | Mainnet |
| Radius Testnet | radius-testnet | 6 | Testnet (free) |
| Solana | solana | 9 | Mainnet |
| Solana Devnet | solana-devnet | 9 | Testnet (free) |
Testnet networks require no API key. Start on base-sepolia or radius-testnet or solana-devnet to test without real funds.
Hosted facilitator
SBC runs a hosted facilitator — no infrastructure to deploy or maintain.
| Value | |
|---|---|
| URL | https://x402.stablecoin.xyz |
| EVM signer | 0xdeE710bB6a3b652C35B5cB74E7bdb03EE1F641E6 |
| Solana signer | 2mSjKVjzRGXcipq3DdJCijbepugfNSJCN1yVN2tgdw5K |
Mainnet networks (base, radius, solana) require an API key passed as the X-API-Key header.
Get yours at dashboard.stablecoin.xyz.
Next
- SDK → — integrate as a server (middleware) or client
- Facilitator API → — HTTP reference and self-hosting