TON Blockchain · Testnet

Pay-per-request APIs
powered by TON

x402 is an open protocol for HTTP micropayments. Protect any API route with a single function, clients pay automatically in BSA USD.

Get the starter →Get testnet BSA USD
// Protect any route in one line
export const GET = paymentGate(handler, {
config: {
amount: "1000000000",
asset: "BSA_USD",
payTo: "UQ...",
}
});

How it works

The full x402 payment flow, step by step

Step 01

Client requests the resource

The client makes a standard HTTP request to a protected API endpoint. No payment is attached yet.

Step 02

Server returns HTTP 402

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.

Step 03

Client builds & signs the payment

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.

Step 04

Client retries with the signed BOC

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.

Step 05

Facilitator verifies & settles on-chain

The facilitator verifies the BOC offline (correct recipient, amount, network), then broadcasts it to the TON blockchain and polls for confirmation.

Step 06

Server unlocks the resource

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.


BSA USD Faucet

Get testnet BSA USD to test the x402 protocol

10BSA USD / claim
30mCooldown
TONTestnet