Skip to content

docs: migrate x402 page to v2, fix facilitator host, document API key - #2229

Merged
viral-sangani merged 2 commits into
mainfrom
GigaHierz/x402-v2-migration
Aug 3, 2026
Merged

docs: migrate x402 page to v2, fix facilitator host, document API key#2229
viral-sangani merged 2 commits into
mainfrom
GigaHierz/x402-v2-migration

Conversation

@GigaHierz

@GigaHierz GigaHierz commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

What

Rewrites build-on-celo/build-with-ai/x402.mdx so the resource-server sample actually works. Three independent problems, all fixed here:

  1. It used the v1 packages (x402-express, nested asset.eip712 price shape, X-PAYMENT header).
  2. It pointed at https://x402.celo.org, which serves the dashboard SPA, not the facilitator API (https://api.x402.celo.org / https://api.x402.sepolia.celo.org).
  3. It never mentioned the API key that POST /settle requires — so an integration looks healthy until its first settlement 401s.

Changes

  • v1 → v2 migration. paymentMiddleware(routes, server) (routes first); payTo + a flat price object ({ amount, asset, extra }) inside each route's accepts[]. Install line npm i @x402/express @x402/core @x402/evm; Hono users swap @x402/express@x402/hono.
  • Facilitator host fixed. Intro prose, <Note>, endpoints table, Resources table, and the sample distinguish the dashboard (x402.celo.org) from the payment API (api.x402.*).
  • API key documented. The sample attaches the key via HTTPFacilitatorClient's createAuthHeaders (keyed by path), reading X402_API_KEY from the server env. New Getting an API Key section covers create/sign on the dashboard, treating the key as a server-side secret, free-then-USDC-funded credits at $0.001/settlement, and a 401/402/429 failure-mode table. The endpoints table marks /settle key-gated vs. the open /verify//supported//health.
  • Headers → v2 (PAYMENT-SIGNATURE).
  • Celo Configuration snippet rewritten as accepts[] entries with explicit asset addresses (mainnet + Celo Sepolia).
  • $0.01 shorthand <Warning>: use the explicit price object until the release carrying Celo's default-asset registry entry ships.
  • USDT domain values (name: "Tether USD", version: "1") moved from asset.eip712 to extra.

v2 is presented as recommended; the facilitator is dual-stack and still serves x402Version: 1 under the legacy network names, so v1 clients are not broken.

Verification

  • Type-checked both code blocks extracted verbatim from the page (via awk, not by hand) against @x402/express@2.20.0 (+ @x402/core, @x402/evm, @types/express) with tsc --noEmit under strictexit 0. The createAuthHeaders return shape ({ verify, settle, supported }, each Record<string,string>) matches FacilitatorConfig; the const routes: RoutesConfig annotation is load-bearing (without it network widens to string and fails the CAIP-2 type — flagged inline).
  • Live curl: POST /settle401 {"error":"unauthorized","message":"Missing X-API-Key"}; /verify reachable without a key (400 on empty body), /supported + /health → 200. GET /supportedx402Version: 2, eip155:42220 (and legacy v1 celo); Celo Sepolia mirror confirmed.
  • mint dev builds; the page renders HTTP 200 warm (the first cold request 500s during Next compile, then 200 in <1s), callout tags balanced (4 open / 4 close).
  • grep -rnE "x402-express|x402-fetch|x402-hono|X-PAYMENT" build-on-celo/ → no hits.

🤖 Generated with Claude Code

@GigaHierz
GigaHierz requested a review from a team as a code owner August 3, 2026 09:40
The resource-server sample used the legacy v1 packages (x402-express,
nested asset.eip712 price shape, X-PAYMENT header) and pointed at
https://x402.celo.org, which serves the dashboard SPA rather than the
facilitator API — so it could not work as written.

- Migrate to the v2 scoped packages (@x402/express, @x402/core, @x402/evm)
  with the paymentMiddleware(routes, server) signature; payTo and a flat
  price object ({ amount, asset, extra }) now live inside each route's
  accepts[] entry.
- Point resource servers at the real facilitator API:
  https://api.x402.celo.org (mainnet) and
  https://api.x402.sepolia.celo.org (Celo Sepolia); the dashboard host is
  called out separately.
- Update payment headers to v2 (PAYMENT-SIGNATURE).
- Rewrite the Celo Configuration snippet as accepts[] entries with explicit
  asset addresses; add a Warning that the "$0.01" shorthand is not yet
  usable on Celo pending the release carrying the default-asset registry.

v2 is presented as recommended; the facilitator remains dual-stack and
still serves x402Version 1 under the legacy network names.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@GigaHierz
GigaHierz force-pushed the GigaHierz/x402-v2-migration branch from 71d4a67 to 66472b3 Compare August 3, 2026 09:43
The facilitator's POST /settle is metered and rejects unauthenticated
requests with 401 {"error":"unauthorized","message":"Missing X-API-Key"}.
/verify, /supported, and /health are open, so an integration looks healthy
until its first settlement — worth calling out explicitly.

- Attach the key in the sample via HTTPFacilitatorClient's createAuthHeaders
  (keyed by path: verify/settle/supported), reading X402_API_KEY from the
  server environment.
- Add a "Getting an API Key" section: create/sign on the dashboard, store it
  as a server-side secret, free credits then USDC-funded credits at $0.001
  per settlement, and a 401/402/429 failure-mode table.
- Mark /settle as key-gated (vs. open) in the endpoints table.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@GigaHierz GigaHierz changed the title docs: migrate x402 page to v2 scoped packages, fix facilitator host docs: migrate x402 page to v2, fix facilitator host, document API key Aug 3, 2026
@viral-sangani
viral-sangani merged commit 6946b28 into main Aug 3, 2026
4 checks passed
@viral-sangani
viral-sangani deleted the GigaHierz/x402-v2-migration branch August 3, 2026 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants