x402 is an open protocol for HTTP micropayments. Protect any API route with a single function, clients pay automatically in BSA USD.
The full x402 payment flow, step by step
The client makes a standard HTTP request to a protected API endpoint. No payment is attached yet.
The server responds with 402 Payment Required and a PAYMENT-REQUIRED header containing the payment details — amount, asset (BSA USD), recipient address, and facilitator URL.
x402Fetch() parses the payment requirements, builds a TEP-74 Jetton transfer BOC on TON, and signs it with the client's wallet key. No transaction is broadcast yet.
The same request is retried with a PAYMENT-SIGNATURE header containing the base64-encoded signed BOC. The server forwards it to the facilitator for verification.
The facilitator verifies the BOC offline (correct recipient, amount, network), then broadcasts it to the TON blockchain and polls for confirmation.
Once the transaction is confirmed on-chain, the server calls the handler and returns the protected resource along with the TX hash in a PAYMENT-RESPONSE header.
Get testnet BSA USD to test the x402 protocol