# x402.md

How an AI agent pays Stacktree for hosting, with no human and no account. The
payment is the credential: no card, no signup. Two paths, multiple rails, all
live on mainnet.

## Rails

- **x402** (the open HTTP 402 standard): USDC on Base (eip155:8453) everywhere, plus USDC on Solana on `https://api.stacktr.ee/publish`, `https://api.stacktr.ee/provision` and the agents.stacktr.ee front-door. v1 and v2 accepted, gasless for the payer. Read the `accepts` array from the 402 rather than assuming a rail: Base is always `accepts[0]`, and the requirements differ per network (an EIP-712 domain on Base, a sponsoring `extra.feePayer` on Solana). The Solana rail is x402 v2; the v1 `X-PAYMENT` rail is Base only, and a v1 payment naming another network is refused rather than settled against Base.
- **MPP** (Machine Payments Protocol, from Stripe and Tempo): USDC.e on Tempo, plus the evm method on Base.
- **Card checkout in a browser**: pay by card in a browser at `https://stacktr.ee/pay`, with no account and no payment client. Any agent with a card can use it, including one paying with ChatGPT's Wallet. It sells two things: keeping one page published without an account ($0.50, one-time, authorized by that page's `claim_token`) and a plan (Solo, Studio or Firm, renews monthly until canceled). The total and the terms are on the page before the pay button, and the card is entered on Stripe's checkout page. As JSON: `POST https://api.stacktr.ee/pay/sessions` with `{"feature":"keep_page","claim_token":"..."}` or `{"feature":"plan","plan":"solo"}` returns `checkout_url`, `amount`, `currency`, `recurring` and `expires_at`.
- **Card pay-link**: a standard Stripe Checkout behind a short URL + terminal QR. A nearby human pays in two taps — or an agent holding its own card credential (for example a single-use virtual card from Stripe's link-cli, US Link accounts) opens the link and fills the checkout itself.

**Take `payTo` from the live 402 envelope, never from your transaction history or an address book entry.** On 1 September 2026 a wallet that had paid us received dust from an address built to look like our payee: same four-character head, same three-character tail, different address. That is standard address poisoning, and a bot is watching payments to us. The receiving address for every rail we accept is also published at `https://api.stacktr.ee/.well-known/x402-service` and `https://api.stacktr.ee/.well-known/x402`: compare the 402's `payTo` against those and refuse the payment if they disagree. Copying an address out of a wallet's "recent" list is how the poisoning pays off.

## 1. Front-door: pay per publish (no key)

The simplest path. Publish a page and pay for that publish, nothing to provision.

- `POST https://agents.stacktr.ee/api/publish` with `{ "html": "..." }`.
- A bare POST returns `402` with the price, assets, and recipient.
- Pay $0.50 over x402 (USDC on Base or Solana) or MPP (Tempo) and retry; the page publishes to a permanent private link returned in the response. A paid one-off sits outside the plan ladder: no expiry, and it does not spend a free-tier page.
- OpenAPI: `https://agents.stacktr.ee/openapi.json`. Listed on x402scan and mppscan.
- The same job, keyless, directly on the API host: `POST https://api.stacktr.ee/publish` at $0.50 over x402 (USDC on Base or Solana) or MPP-evm. Free proof-of-service record, read it before you spend: `https://api.stacktr.ee/.well-known/x402-service`.

### Revising the page you paid for (free, no key)

Do not pay again to update. Paying again mints a SECOND page at a different
URL and charges you twice for one deliverable. Two keyless credentials replace
the content at the same URL, and the page's response already handed you the
first one.

**Any rail, one request: the page's own claim token.** While the page is
unclaimed (a paid one-off is unclaimed until someone adopts it, and it never
expires), the `claim_token` from the publish response is its update
credential:

```
PUT https://api.stacktr.ee/sites/{id}
Authorization: Claim <claim_token>
Content-Type: application/json         {"html": "<!doctype html>..."}
```

The body is the same shape you published with, which is the point: `POST
/publish` takes `{"html": ...}`, so a revision is the same JSON at a different
verb. (`multipart/form-data` with a `file` field also works, and is the only
shape that carries a zip, a PDF, or e2e ciphertext.)

No signature, no challenge, no account, and it works on Solana and Base alike.
Scope is that one page's content and nothing else. It stops working the moment
the page is claimed into an account (the claim rotates the token), which is the
handover, not a fault. Treat the token as being as sensitive as the page: it
replaces the content behind a link you may already have sent.

**EVM only. It outlives the claim token, but not unconditionally: after a claim it keeps working only while the wallet stays linked to the account that claimed the page.**

- `POST https://api.stacktr.ee/wallet-auth/challenge` with `{ "wallet": "0x…" }` (the
  wallet that paid) — returns `{ challenge, message, expires_at }`.
- `personal_sign` (EIP-191) the `message` with that wallet — the same signing
  step as wallet linking; no transaction, no fee.
- `PUT https://api.stacktr.ee/sites/{id}` with `{"html": "..."}` as
  `application/json` (or the multipart `file` field) and
  `Authorization: Wallet challenge=WAUTH-…,sig=0x…`. Same URL, new
  content. Challenges are single-use with a 5-minute TTL, one per update.
- EVM EOA wallets only for now (no smart-contract wallets / EIP-1271). Paid on
  Solana or with a contract wallet? Use the claim-token request above: same
  URL, same price of nothing, no signature to produce.

### Everything this wallet has paid for

A wallet-paid publish response carries `next.receipt_url`, a stable link to a
page listing every page that wallet has paid for: title, URL, date, the
settlement on chain, whether the claim token is still live, the exact request
that revises each one, and a button to move them all into an account. It is the
same link every time that wallet pays, so it is worth keeping.

The link IS the credential. We do not accept the payer address in its place,
because payer addresses are public on chain and an address-keyed page would let
anyone read a customer's private page titles off a block-explorer list. For the
same reason `POST https://api.stacktr.ee/wallet-auth/challenge` does not return it: that
endpoint gates only on "this wallet is known here". Lost the link? Make one free
revision with the wallet that paid (the three steps above) and the response
carries `receipt_url` again.

## 2. Persistent key: provision once, pay as you go

For an agent that publishes repeatedly.

- `GET https://api.stacktr.ee/provision` returns the rail menu (which protocols are live).
- `POST https://api.stacktr.ee/provision` carries the payment. A bare POST returns `402` with a `PAYMENT-REQUIRED` header (x402) or a `WWW-Authenticate: Payment` challenge (MPP). Pay $1 in USDC on Base (`accepts[0]`) or on Solana (`accepts[1]`) and you receive a persistent `stk_live_` API key, shown once. The key itself is the credential afterwards, whichever rail paid for it.
- Send the key as `Authorization: Bearer stk_live_...` on subsequent requests.

The key starts on free-tier limits: 3 pages in total (deleting one does not free
the slot), every page expiring after 7 days, no email gates, no viewer numbers
(passcodes do work on the free tier, up to three).
Publishing past a limit returns `402` with a `plan_*` error code. Lift them with
an unlock below, or point your human at a plan.

### Unlocks (a-la-carte, same rails)

- `POST https://api.stacktr.ee/unlock?feature=make_permanent` ($5, one-time, per site) — cancels the expiry on one page.
- `POST https://api.stacktr.ee/unlock?feature=custom_domain` ($5 / 30 days) — serve on your own hostname.
- `POST https://api.stacktr.ee/unlock?feature=higher_limits` ($25 / 30 days) — fleet limits: 1 GB per site, unlimited daily publishes, no page cap, pages that do not expire.
- `GET https://api.stacktr.ee/unlock` for the live catalog. It is authoritative over this file.

## 3. Pay link: card payments, human-approved or agent-driven

For an agent with no wallet. Two ways to complete it:

- `POST https://api.stacktr.ee/pay/sessions` with `{ "feature": "provision" }` (no auth).
- The response includes a short URL and a ready-to-print terminal QR (`qr` field). **Human path:** they scan and pay by card, about two taps. **Agent path:** the checkout behind the URL is standard Stripe Checkout — an agent holding a human-approved single-use card (e.g. `npx @stripe/link-cli`, currently US Link accounts only) can open the URL, continue to checkout, and fill it directly. Their credentials are amount-locked and single-use: create the spend request for the exact checkout total, and complete before the approval window closes.
- Poll `GET https://api.stacktr.ee/pay/sessions/{code}/poll`; on `provision` it returns the API key once.
- Pay above the price (up to $20) and the surplus becomes a prepaid balance that future paid actions draw from silently, with no new 402.

## Wiring it up

Give your agent any x402 client (e.g. @x402/fetch) or MPP client (e.g. mppx) and a funded wallet, point it at the endpoint, and the 402 is handled automatically. Gas is covered, so the agent only signs.

A permanent page from Node, paying $0.50 in USDC on Base (`npm install @x402/fetch @x402/evm viem`):

```js
import { wrapFetchWithPaymentFromConfig } from '@x402/fetch';
import { ExactEvmScheme } from '@x402/evm';
import { privateKeyToAccount } from 'viem/accounts';

const account = privateKeyToAccount(process.env.WALLET_PRIVATE_KEY); // holds USDC on Base
const payingFetch = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: 'eip155:8453', client: new ExactEvmScheme(account) }],
});
const res = await payingFetch('https://api.stacktr.ee/publish', {
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: JSON.stringify({ html: '<!doctype html><html>...</html>' }),
});
const page = await res.json(); // page.url is the link; keep page.claim_token to revise it
```

The body is checked before the payment settles: a request we cannot publish (no `html`, too large) is refused with a 4xx and never charged.

x402 is a signature, not a transfer. Do not send USDC to `payTo` yourself: a plain transfer pays for no request and publishes nothing. The client signs an authorization, we hand it to the facilitator, and the facilitator moves the funds and pays the gas.

## Machine-readable

- Front-door OpenAPI: `https://agents.stacktr.ee/openapi.json`
- HTTP API OpenAPI: `https://api.stacktr.ee/openapi.json`
- Auth and registration: `https://stacktr.ee/auth.md`
- Human pages: `https://stacktr.ee/x402` and `https://stacktr.ee/mpp`
