Skip to content

Upgrade x402 from v1 to v2#39

Open
racket2000 wants to merge 3 commits into
mainfrom
upgrade-x402-v2
Open

Upgrade x402 from v1 to v2#39
racket2000 wants to merge 3 commits into
mainfrom
upgrade-x402-v2

Conversation

@racket2000

@racket2000 racket2000 commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Summary

Migrates all four x402 touchpoints — the Python agentic client, both seller Lambdas, and the React frontend — to the x402 v2 wire format, and unpins the Python SDK (x402>=0.1.0,<1.0x402[httpx,evm]>=2.0.0,<3.0). The old pin
existed because v2 broke the x402.clients.httpx imports; this PR adopts the v2 API instead.

Wire format changes (applied consistently everywhere)

  • x402Version 12
  • maxAmountRequiredamount
  • network "base-sepolia" → CAIP-2 "eip155:84532"
  • resource/description/mimeType hoisted to a top-level resource object
    on the 402 body
  • Payment payload now carries the full accepted requirements object (the
    live facilitator rejects flat scheme/network; the current TS SDK schema is
    stale on this)
  • PAYMENT-SIGNATURE only — dropped the v1 X-PAYMENT fallback (CORS updated
    in CDK too)

Python client (agentic/wallet.py)

  • Rewrote get_x402_httpx_client to the v2 API:
    x402Client().register("eip155:*", ExactEvmScheme(signer)) +
    register_policy(prefer_network/prefer_scheme), wrapped by
    x402HttpxClient(client, base_url=...)
  • Replaced the 3-arg signing adapter with _CdpWalletSigner implementing the
    v2 ClientEvmSigner protocol (4-arg sign_typed_data returning raw bytes)
  • Added to_caip2() network mapping

Sellers (serverless/lambda/seller/seller.js, agentic/lambda/seller.js)

  • Build and send the v2 accepted object on both /verify and /settle
  • Point directly at the canonical www.x402.org/facilitator — the apex
    x402.org 308-redirects every call to www, so this avoids a redirect
    round-trip per payment. The existing redirect handlers stay as a harmless
    fallback.
  • Seller remains the source of truth for the authorized amount

Verification

Tested end-to-end against the live facilitator:

  • Signed EIP-712 v2 round-trip recovers the correct payer
    (insufficient_balance on a throwaway key = format correct)
  • Both sellers run locally: serverless through verify → generate → settle with
    a valid PAYMENT-RESPONSE header; agentic through deferred settle-by-nonce
  • Confirmed sellers hit www.x402.org with a single 200 (no redirect hop)
  • Frontend tsc --noEmit clean and vite build succeeds

Simon Goldberg and others added 3 commits June 16, 2026 15:03
Migrate all four x402 touchpoints (Python agentic client, both seller
Lambdas, React frontend) to the x402 v2 wire format, and unpin the
Python SDK.

Wire format (applied consistently):
- x402Version 1 -> 2
- maxAmountRequired -> amount
- network "base-sepolia" -> CAIP-2 "eip155:84532"
- resource/description/mimeType hoisted to a top-level resource object
  on the 402 body
- payment payload now carries the full `accepted` requirements object
  (flat scheme/network is rejected by the live facilitator)
- PAYMENT-SIGNATURE only (dropped X-PAYMENT v1 fallback)

Python client (agentic/wallet.py, requirements.txt):
- x402>=0.1.0,<1.0 -> x402[httpx,evm]>=2.0.0,<3.0
- rewrite get_x402_httpx_client to v2 API: x402Client().register(...) +
  register_policy(prefer_network/prefer_scheme), x402HttpxClient(client, ...)
- replace 3-arg adapter with _CdpWalletSigner implementing the v2
  ClientEvmSigner protocol (4-arg sign_typed_data returning raw bytes)
- add to_caip2() network mapping

Sellers (serverless + agentic seller.js):
- build/send the v2 accepted object on verify and settle
- point directly at canonical www.x402.org/facilitator (apex 308-redirects
  to www on every call) to avoid a redirect round-trip per payment
- seller remains source of truth for the authorized amount

Verified end-to-end against the live facilitator: signed EIP-712 v2
round-trip recovers the correct payer; both sellers run locally through
verify -> generate -> settle (serverless) and deferred settle-by-nonce
(agentic); frontend typechecks and builds.
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.

1 participant