feat: migrate x402-proxy-template to x402 v2 with Solana support - #1087
Open
notorious-d-e-v wants to merge 3 commits into
Open
feat: migrate x402-proxy-template to x402 v2 with Solana support#1087notorious-d-e-v wants to merge 3 commits into
notorious-d-e-v wants to merge 3 commits into
Conversation
notorious-d-e-v
force-pushed
the
feat/x402-v2-solana
branch
from
July 31, 2026 06:15
f52b471 to
a52cd57
Compare
Author
|
Pushed a follow-up based on private feedback from @phdargen -- the feedback was that the template still has a lot of x402 v1 artifacts. Now the v1-era network aliases are removed entirely. All alias/legacy mentions are gone from the docs as well. |
Replace legacy x402-hono v1 middleware with @x402/hono 2.19.0. NETWORK now accepts CAIP-2 identifiers (legacy aliases still resolve), one or many via comma-separated list; each protected route advertises one payment option per configured network. Adds PAY_TO_SOLANA for solana:* networks, memoizes the payment middleware so facilitator sync runs once per isolate, migrates the test client to @x402/fetch with optional EVM/Solana signers, and updates the Playwright spec to the v2 wire format (PAYMENT-REQUIRED header).
Co-authored-by: Ethan Oroshiba <ethan.oroshiba@gmail.com>
Remove the v1-era network aliases per review feedback. NETWORK now takes CAIP-2 identifiers exclusively; configs using an old name get an explicit error pointing at the CAIP-2 format.
notorious-d-e-v
force-pushed
the
feat/x402-v2-solana
branch
from
August 12, 2026 14:51
2b0e657 to
c28ff94
Compare
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
Upgrades
x402-proxy-templatefrom x402 v1 to the current v2 protocol (@x402/*2.19.0) and adds Solana support alongside Base. The legacyx402-*v1 packages haven't shipped since April 2026, and the template was hard-coded to a single EVM network.Out of the box the template now advertises Base Sepolia and Solana devnet payment options on every protected route.
NETWORKtakes CAIP-2 identifiers (single or comma-separated) — the v1-era friendly names are gone entirely; a config still using one gets an explicit error naming the CAIP-2 format to switch to.What changed
x402-hono→@x402/honowith EVM + Solana schemes registered per configured network.PAY_TO_SOLANAvar for Solana recipients (defaults to the well-known incinerator, mirroring the existing0x…dEaDtesting default).test-client.ts) rewritten on@x402/fetch— works with an EVM key, a Solana key, or both.@coinbase/x402dependency and the legacyx402dev dependency.Verification
Settled real USDC end-to-end (402 → pay → verify → settle → JWT cookie → cookie-only re-access) on all four networks, each confirmed on-chain:
x402.org/facilitator:0xcceef5…d46b95ex402.org/facilitator:DsvS3mgZ…pQdTtDwfacilitator.payai.network:0x5676db…49fe35efacilitator.payai.network:3M8mbwoc…owr5kTa258nvX9v…1NRqiPpChecks:
npm run lintclean, Playwright 5/5,pnpm run checkgreen.Notes for AI Agent Reviewers
Implementation and verification detail
Implementation
src/auth.ts): anx402ResourceServerregistersExactEvmSchemeforeip155:*andExactSvmSchemeforsolana:*networks, wrapped by@x402/hono'spaymentMiddleware. The middleware is memoized at module scope keyed by a fingerprint of (facilitator URL, networks, recipients, route config), so the facilitator/supportedsync runs once per isolate instead of per request. Measured: first protected request ~620 ms (sync), subsequent ~8 ms./*-suffix patterns are converted to x402 v2 route patterns whose compiled regexes are a strict superset of the template'sstartsWithsemantics;index.tsremains the outer gate, and both matchers are first-match-in-insertion-order, so pricing selection is consistent.eip155:*,solana:*). Non-CAIP-2 entries (including pre-v2 names likebase-sepolia) and missing per-family recipients return a JSON 500 config error with guidance (matching the existingJWT_SECRETerror pattern) rather than crashing.PAY_TOcoverseip155:*;PAY_TO_SOLANAcoverssolana:*and defaults to1nc1nerator11111111111111111111111111111111, whose devnet USDC token account already exists — necessary because the v2exactSVM scheme (unlike v1) does not create the recipient's associated token account, so a fresh address fails verification with a simulation error until it has received the token once. This constraint is documented in the README and wrangler comments.nodejs_compatcompatibility flag added — the v2 middleware usesBufferin its settlement path.wrapFetchWithPayment+x402Clientwith optional EVM (PRIVATE_KEY) and Solana (SOLANA_PRIVATE_KEY,SOLANA_RPC_URL) signers; the client pre-filters the server'sacceptsto registered schemes, so either key works alone. AddedTARGET_PATHoverride (defaults to/premium; the built-in/__x402/protectedworks without configuring an origin), prints the decodedPAYMENT-RESPONSEsettlement receipt (network + tx hash), surfaces decoded rejection reasons on failed payments, and consumes response bodies so the process exits cleanly.PAYMENT-REQUIREDheader,x402Version: 2, both default accepts (including the incinerator payTo and facilitator-injectedextra.feePayer), and the SDK's static HTML fallback for browser requests when@x402/paywallisn't installed.Compatibility
@x402/fetch—test-client.tsshows the pattern.https://x402.org/facilitator) verifies both shipped testnets, including the Solana devnet fee-payer sponsorship (extra.feePayer) the SVM scheme requires. Payers need no ETH/SOL: EVM payments are signed offline (EIP-3009) and Solana fees are sponsored viaextra.feePayer; the facilitator submits transactions.Additional manual verification (
wrangler dev)GET /__x402/health→ 200;GET /__x402/config→ resolved networks + masked per-family recipients.GET /__x402/protected(default config) → 402 whose decodedPAYMENT-REQUIREDcarries both accepts —eip155:84532(USDC, amount10000) andsolana:EtWT…(devnet USDC mint4zMMC9…,extra.feePayerinjected).NETWORK="base-sepolia"→ explicit 500 config error:unknown NETWORK entry "base-sepolia"; use CAIP-2 identifiers such as eip155:84532.PAY_TO_SOLANA→ JSON 500 config error.Accept: text/html→ 402 HTML fallback page.🤖 Generated with Claude Code