x402 Pay-Per-Call

Interactive front end for the Lean model in Poc/X402.lean · HTTP 402 → payment header → paid content

Step 1 — Request

The client requests the paid resource with no payment header:

GET http://127.0.0.1:8402/paid/report
(no X-PAYMENT header)

The server cannot serve paid content yet — it answers with a payment challenge. Continue to Step 2.

Step 2 — HTTP 402 Challenge

HTTP 402  Payment Required

Exact challenge JSON from the Lean demo:


  

Step 3 — Build payment

Payload JSON built from accepts[0] (exact string, key order matters):


    

X-PAYMENT header — base64 of the payload above:


    

Header length: chars (expected 428 with the correct defaults).

Step 4 — Retry + verify (stub)

The client retries GET http://127.0.0.1:8402/paid/report with the X-PAYMENT header. The server runs a JS shape-check mirroring the Lean validator, in order:

  1. base64 decodes
  2. x402Version == 1
  3. scheme == "exact"
  4. network == requirements.network ("solana")
  5. payload.signature present and non-empty

Not run yet. Click “Run shape-check (stub)”.

Step 5 — Paid content

Locked: Step 4 must ACCEPT first. Run the shape-check in Step 4 — if it rejects (for example after tampering), no content is served.

Source of truth: Poc/X402.lean in this repository. This page works from file:// — no frameworks, no CDN, no external assets, no network calls.