# Example: an x402 client

The x402 payment handshake from the buyer's side: request a paid resource, receive 402 with payment requirements, sign the authorization with your own key, retry, and walk away with the resource plus a quitanza proving the matter closed. The example starts a local API in-process.

From a checkout of the Quitanza repository:

```
pnpm install
pnpm exec tsx examples/x402-client.ts
```

## What it shows

1. **The offer**: a bare GET returns `402` with machine-readable payment requirements: amount, asset, resource, and where to pay.
2. **Acceptance is a signature**: `createPaymentHeader` signs the payment authorization with the buyer's key, client-side, and the retry carries it in `X-PAYMENT`.
3. **Settlement rides the response**: `X-PAYMENT-RESPONSE` names the escrow and the quitanza; behind one round trip the full lifecycle ran, create, fund, deliver, verify.
4. **The proof is first-class**: the quitanza verifies like any other, API or offline.

## The shape of it

```ts
const offer = await fetch(url); // 402 + requirements
const header = createPaymentHeader(offer.accepts[0], buyerKeys);
const paid = await fetch(url, { headers: { "x-payment": header } });
const settled = decodePaymentResponse(paid.headers.get("x-payment-response"));
await qz.quitanzas.verify(settled.quitanzaId); // all true
```

One HTTP round trip more than a free request, one proof more too. The server side of this handshake is described on the [x402 adapter page](/docs/x402.html).
