Verify. Settle.
Issue receipts.
The x402 payment protocol turns any HTTP endpoint into a paid resource. Users sign once. The facilitator settles on Base. Receipts enable repeat access without re-payment.
Three-call settlement
POST /verify
Validate the EIP-3009 authorization. Checks signature, amount match, nonce freshness, expiry, and gas price. Returns valid: true or a structured error code.
Reference →POST /settle
Execute the on-chain transfer. Facilitator calls transferWithAuthorization on USDC. Returns txHash, payer, and requestId. Gas is paid by the facilitator — not the user.
Reference →Issue receipt
Bind the txHash to a receipt with a TTL. The receipt ID is presented on repeat requests to skip re-settlement. Reduces cost for high-frequency access.
Reference →Pay once. Access many.
After settlement, issue a receipt with a TTL. Present the receipt ID on subsequent requests — the server verifies it without triggering a new settlement.
GET /api/v1/receipts/rcpt_01HX.../verify
Authorization: Bearer $P402_API_KEY
# Response (valid):
{
"valid": true,
"reuseCount": 4,
"expiresAt": "2025-01-01T01:00:00Z",
"resource": "https://your-api.com/endpoint"
}
# Response (expired):
{
"valid": false,
"reason": "RECEIPT_EXPIRED",
"requestId": "req_..."
}Common errors and fixes
AMOUNT_MISMATCHREPLAY_DETECTEDAUTHORIZATION_EXPIREDGAS_PRICE_TOO_HIGHINVALID_SIGNATUREAll errors include a requestId field. Include it when contacting support.
Drop-in integration
The @p402/sdk handles verify, settle, retry, and receipt reuse automatically. For custom flows, use the REST API directly.
import { p402Fetch } from '@p402/sdk';
// Drop-in fetch replacement.
// Handles 402 → sign → settle → retry automatically.
const res = await p402Fetch('https://your-api.com/endpoint', {
wallet: yourWallet,
maxAmount: 1_000_000n, // $1.00 USDC
});
// res is the successful endpoint response.
// Receipt is stored automatically for reuse.