Upgrade x402 from v1 to v2#39
Open
racket2000 wants to merge 3 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.0→x402[httpx,evm]>=2.0.0,<3.0). The old pinexisted because v2 broke the
x402.clients.httpximports; this PR adopts the v2 API instead.Wire format changes (applied consistently everywhere)
x402Version1→2maxAmountRequired→amountnetwork"base-sepolia"→ CAIP-2"eip155:84532"resource/description/mimeTypehoisted to a top-levelresourceobjecton the 402 body
acceptedrequirements object (thelive facilitator rejects flat
scheme/network; the current TS SDK schema isstale on this)
PAYMENT-SIGNATUREonly — dropped the v1X-PAYMENTfallback (CORS updatedin CDK too)
Python client (
agentic/wallet.py)get_x402_httpx_clientto the v2 API:x402Client().register("eip155:*", ExactEvmScheme(signer))+register_policy(prefer_network/prefer_scheme), wrapped byx402HttpxClient(client, base_url=...)_CdpWalletSignerimplementing thev2
ClientEvmSignerprotocol (4-argsign_typed_datareturning raw bytes)to_caip2()network mappingSellers (
serverless/lambda/seller/seller.js,agentic/lambda/seller.js)acceptedobject on both/verifyand/settlewww.x402.org/facilitator— the apexx402.org308-redirects every call towww, so this avoids a redirectround-trip per payment. The existing redirect handlers stay as a harmless
fallback.
Verification
Tested end-to-end against the live facilitator:
(
insufficient_balanceon a throwaway key = format correct)a valid
PAYMENT-RESPONSEheader; agentic through deferred settle-by-noncewww.x402.orgwith a single 200 (no redirect hop)tsc --noEmitclean andvite buildsucceeds