x402 micropayment, live demo.
Buy a compliance report from StableKYA.com for $0.001 testnet USDC. Watch every stage of the payment lifecycle as it happens.
Your Wallet
The x402 journey begins when you delegate spending authority by connecting a wallet. Your wallet's identity — address and chain — becomes the foundation for every compliance check that follows.
The Gate
When any HTTP client — browser, CLI, or AI agent — hits a paywalled resource, the server responds with HTTP 402 Payment Required. The payment requirements are encoded in the response headers. The server doesn't know or care what the client is.
The Payment
You sign an EIP-3009 transferWithAuthorization — a gasless USDC transfer that the CDP facilitator submits on your behalf. OFAC screening fires at S6 as a code-enforced gate before the transfer lands on-chain.
The Delivery
On successful payment, the server responds with 200 OK and delivers the compliance report as a PDF. The settlement receipt includes the transaction hash, block number, and finality time. The loop closes: the diagram inside the PDF maps the transaction you just made.
Know Your Agent: Anatomy of an x402 Compliant Transaction
The compliance diagram inside this report maps the transaction you just completed.
The Code
The payment flow code — buyer site and publisher Worker — is open source. The server is ~40 lines. The client is ~60. The STP Sequence and Stablecoin Stack compliance diagrams are not.
// stablekya.com/api/report — x402 gate
export default {
async fetch(request: Request, env: Env) {
const paymentSig = request.headers
.get('PAYMENT-SIGNATURE');
if (!paymentSig) {
return new Response('Payment Required', {
status: 402,
headers: {
'PAYMENT-REQUIRED': btoa(JSON.stringify({
accepts: [{
scheme: 'exact',
network: 'base-sepolia',
asset: 'USDC',
amount: '1000',
payTo: env.MERCHANT_ADDRESS,
resource: 'kya-compliance-report-v1',
}],
})),
},
});
}
// Verify payment via facilitator...
const report = await env.REPORTS
.get('kya-report-v1.pdf');
return new Response(report.body, {
headers: {
'Content-Type': 'application/pdf',
},
});
},
}; // Stable402.com — x402 buyer flow
async function purchaseReport() {
// 1. Hit the gate
const res402 = await fetch(
'https://stablekya.com/api/report'
);
const requirements = JSON.parse(atob(
res402.headers.get('PAYMENT-REQUIRED')
)).accepts[0];
// 2. Sign EIP-3009 authorization
const signature = await walletClient
.signTypedData({
domain: {
name: 'USDC', version: '2',
chainId: 84532,
verifyingContract: USDC,
},
types: {
TransferWithAuthorization: [
/* from, to, value, ... */
],
},
message: {
from: address,
to: requirements.payTo,
value: BigInt(requirements.amount),
},
});
// 3. Retry with payment
const res200 = await fetch(
'https://stablekya.com/api/report',
{
headers: {
'PAYMENT-SIGNATURE': btoa(
JSON.stringify({
x402Version: 2,
accepted: requirements,
payload: { signature },
})
),
},
}
);
// 4. Deliver the PDF
const pdf = await res200.blob();
downloadPdf(pdf, 'kya-report.pdf');
}