-
Notifications
You must be signed in to change notification settings - Fork 620
[SDK] Deprecate payTo parameter and simplify facilitator implementation #8177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SDK] Deprecate payTo parameter and simplify facilitator implementation #8177
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughRemoved the user-editable payTo input and all runtime payTo handling; payTo is now derived from the facilitator address. Middleware uses a pre-initialized facilitator instead of per-request creation. Schemas/types add optional errorMessage fields and adjust verify/settle responses. Signing uses the to address as the ERC-2612 spender. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant UI as Playground UI
participant MW as Middleware
participant FAC as Facilitator (twFacilitator)
participant X402 as X402 Library
participant CH as Chain
note over UI: No user-provided payTo
UI->>MW: Initiate payment (chainId, request)
MW->>FAC: Use pre-initialized twFacilitator
MW->>X402: verifyPayment(request, facilitator)
X402->>FAC: verify(...)
FAC-->>X402: FacilitatorVerifyResponse (ok | {error, errorMessage})
alt verified
X402-->>MW: { verified: true }
MW->>X402: settlePayment(..., facilitator, waitUntil)
X402->>CH: Execute settlement (payTo = facilitator.address)
CH-->>X402: Result (ok | fail with errorMessage)
X402-->>MW: { ok | {error, errorMessage} }
else not verified
X402-->>MW: { error, errorMessage }
end
MW-->>UI: Response (includes error and optional errorMessage)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (10)
💤 Files with no reviewable changes (2)
🚧 Files skipped from review as they are similar to previous changes (3)
🧰 Additional context used📓 Path-based instructions (5)**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/*.{ts,tsx,js,jsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
**/types.ts📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/thirdweb/**/*.{ts,tsx}📄 CodeRabbit inference engine (AGENTS.md)
Files:
apps/{dashboard,playground-web}/**/*.{ts,tsx}📄 CodeRabbit inference engine (CLAUDE.md)
Files:
🧬 Code graph analysis (3)apps/playground-web/src/middleware.ts (1)
packages/thirdweb/src/x402/sign.ts (1)
packages/thirdweb/src/x402/facilitator.ts (1)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
🔇 Additional comments (11)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
Comment |
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/thirdweb/src/x402/facilitator.ts (1)
175-175: Fix type cast to match method signature.The method signature declares
Promise<FacilitatorVerifyResponse>but line 175 casts toVerifyResponse. This creates a type inconsistency.Apply this diff to fix the type cast:
const data = await res.json(); - return data as VerifyResponse; + return data as FacilitatorVerifyResponse; },
🧹 Nitpick comments (1)
apps/playground-web/src/middleware.ts (1)
33-38: Consider making the error message more specific.The error message "Missing required parameters" is now slightly generic since only
chainIdis validated. Consider updating it to "Missing required parameter: chainId" for clarity.Apply this diff to improve error message specificity:
if (!chainId) { return NextResponse.json( - { error: "Missing required parameters" }, + { error: "Missing required parameter: chainId" }, { status: 400 }, ); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (9)
apps/playground-web/src/app/payments/x402/components/X402LeftSection.tsx(0 hunks)apps/playground-web/src/middleware.ts(3 hunks)packages/thirdweb/src/x402/common.ts(2 hunks)packages/thirdweb/src/x402/facilitator.ts(3 hunks)packages/thirdweb/src/x402/schemas.ts(2 hunks)packages/thirdweb/src/x402/settle-payment.ts(2 hunks)packages/thirdweb/src/x402/sign.ts(2 hunks)packages/thirdweb/src/x402/types.ts(2 hunks)packages/thirdweb/src/x402/verify-payment.ts(2 hunks)
💤 Files with no reviewable changes (1)
- apps/playground-web/src/app/payments/x402/components/X402LeftSection.tsx
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from@/typesor localtypes.tsbarrels
Prefer type aliases over interface except for nominal shapes
Avoidanyandunknownunless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial,Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
**/*.{ts,tsx}: Use explicit function declarations and explicit return types in TypeScript
Limit each file to one stateless, single‑responsibility function
Re‑use shared types from@/typeswhere applicable
Prefertypealiases overinterfaceexcept for nominal shapes
Avoidanyandunknownunless unavoidable; narrow generics when possible
Prefer composition over inheritance; use utility types (Partial, Pick, etc.)
Lazy‑import optional features and avoid top‑level side‑effects to reduce bundle size
Files:
packages/thirdweb/src/x402/schemas.tspackages/thirdweb/src/x402/facilitator.tsapps/playground-web/src/middleware.tspackages/thirdweb/src/x402/types.tspackages/thirdweb/src/x402/common.tspackages/thirdweb/src/x402/verify-payment.tspackages/thirdweb/src/x402/settle-payment.tspackages/thirdweb/src/x402/sign.ts
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)
Files:
packages/thirdweb/src/x402/schemas.tspackages/thirdweb/src/x402/facilitator.tsapps/playground-web/src/middleware.tspackages/thirdweb/src/x402/types.tspackages/thirdweb/src/x402/common.tspackages/thirdweb/src/x402/verify-payment.tspackages/thirdweb/src/x402/settle-payment.tspackages/thirdweb/src/x402/sign.ts
packages/thirdweb/**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
packages/thirdweb/**/*.{ts,tsx}: Every public symbol must have comprehensive TSDoc with at least one compiling@exampleand a custom tag (@beta,@internal,@experimental, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose
Lazy‑load heavy dependencies inside async paths (e.g.,const { jsPDF } = await import("jspdf"))
Files:
packages/thirdweb/src/x402/schemas.tspackages/thirdweb/src/x402/facilitator.tspackages/thirdweb/src/x402/types.tspackages/thirdweb/src/x402/common.tspackages/thirdweb/src/x402/verify-payment.tspackages/thirdweb/src/x402/settle-payment.tspackages/thirdweb/src/x402/sign.ts
apps/{dashboard,playground-web}/**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
apps/{dashboard,playground-web}/**/*.{ts,tsx}: Import UI primitives from@/components/ui/*(Button, Input, Select, Tabs, Card, Sidebar, Badge, Separator) in dashboard and playground apps
UseNavLinkfor internal navigation with automatic active states in dashboard and playground apps
Use Tailwind CSS only – no inline styles or CSS modules
Usecn()from@/lib/utilsfor conditional class logic
Use design system tokens (e.g.,bg-card,border-border,text-muted-foreground)
Server Components (Node edge): Start files withimport "server-only";
Client Components (browser): Begin files with'use client';
Always callgetAuthToken()to retrieve JWT from cookies on server side
UseAuthorization: Bearerheader – never embed tokens in URLs
Return typed results (e.g.,Project[],User[]) – avoidany
Wrap client-side data fetching calls in React Query (@tanstack/react-query)
Use descriptive, stablequeryKeysfor React Query cache hits
ConfigurestaleTime/cacheTimein React Query based on freshness (default ≥ 60s)
Keep tokens secret via internal API routes or server actions
Never importposthog-jsin server components
Files:
apps/playground-web/src/middleware.ts
**/types.ts
📄 CodeRabbit inference engine (AGENTS.md)
Provide and re‑use local type barrels in a
types.tsfile
Files:
packages/thirdweb/src/x402/types.ts
🧬 Code graph analysis (4)
packages/thirdweb/src/x402/facilitator.ts (1)
packages/thirdweb/src/x402/schemas.ts (1)
FacilitatorVerifyResponse(66-68)
apps/playground-web/src/middleware.ts (2)
packages/thirdweb/src/x402/facilitator.ts (1)
facilitator(107-262)packages/thirdweb/src/exports/x402.ts (1)
facilitator(3-3)
packages/thirdweb/src/x402/common.ts (2)
packages/thirdweb/src/x402/facilitator.ts (1)
facilitator(107-262)packages/thirdweb/src/exports/x402.ts (1)
facilitator(3-3)
packages/thirdweb/src/x402/sign.ts (1)
packages/thirdweb/src/x402/schemas.ts (2)
RequestedPaymentRequirements(50-52)networkToChainId(108-129)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
- GitHub Check: E2E Tests (pnpm, vite)
- GitHub Check: Size
- GitHub Check: E2E Tests (pnpm, webpack)
- GitHub Check: E2E Tests (pnpm, esbuild)
- GitHub Check: Lint Packages
- GitHub Check: Build Packages
- GitHub Check: Analyze (javascript)
🔇 Additional comments (14)
apps/playground-web/src/middleware.ts (2)
16-22: LGTM! Pre-initializing the facilitator improves performance.Moving the facilitator initialization to module scope avoids recreating it on every request, which is a performance improvement. The configuration correctly uses environment variables and the facilitator function signature.
62-63: LGTM! Clean separation of concerns.Passing
waitUntilandfacilitatoras separate parameters tosettlePaymentproperly separates facilitator configuration from per-request timing preferences. This aligns with the simplification goals of the PR.packages/thirdweb/src/x402/types.ts (2)
52-55: LGTM! Error response structure improved.The addition of
errorMessagealongsideerrorprovides better error messaging capabilities. The field descriptions clearly distinguish between error code and human-readable message.
37-38:payTodeprecation change is backward-compatible. Changing from a required Address to an optional string does not break existing calls, as Address is assignable to string.packages/thirdweb/src/x402/verify-payment.ts (2)
104-117: LGTM! Error handling improved with dual error fields.The introduction of separate
error(code) anderrorMessage(human-readable) fields provides better error context. The fallback chain is well-structured:
- Custom error messages from config
- Facilitator-provided error messages
- Default/generic messages
127-130: LGTM! Consistent error handling in catch block.The catch block properly distinguishes between error code (
"Verification error") and error message, with appropriate type guards for theErrorinstance.packages/thirdweb/src/x402/common.ts (2)
139-139: LGTM! Comment clarification.The updated comment "decode b64 payment" is more accurate than "Verify payment" since this section only decodes the payment data without verifying it.
107-107: LGTM—facilitator.address guaranteed
All calls to decodePaymentRequest (in verify-payment.ts and settle-payment.ts) destructure and pass facilitator, so using facilitator.address for payTo is safe.packages/thirdweb/src/x402/settle-payment.ts (2)
159-172: LGTM! Settlement error handling mirrors verification pattern.The error handling structure is consistent with
verify-payment.ts, using separateerroranderrorMessagefields with the same fallback chain. This consistency improves maintainability.
182-185: LGTM! Consistent catch block error handling.The catch block follows the same pattern as verification, properly distinguishing error code from error message.
packages/thirdweb/src/x402/facilitator.ts (2)
8-8: LGTM! Import updated for new response type.The import of
FacilitatorVerifyResponsecorrectly replaces the genericVerifyResponseimport for facilitator-specific verification.
39-39: LGTM! Method signature updated correctly.The
verifymethod now correctly returnsFacilitatorVerifyResponse, which includes the optionalerrorMessagefield.Also applies to: 152-152
packages/thirdweb/src/x402/sign.ts (2)
266-266: LGTM! Spender correctly uses recipient address.The change to use
toas the spender in the Permit message is correct and aligns with the ERC-2612 standard where the spender is the address authorized to transfer tokens on behalf of the owner.
233-234: LGTM—signature simplified by usingtoparameter.Verify that the
ExactEvmPayloadAuthorizationtype definition includes thetofield.
size-limit report 📦
|
7bced32 to
b04f00e
Compare
b04f00e to
f6a2994
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8177 +/- ##
=======================================
Coverage 56.29% 56.29%
=======================================
Files 906 906
Lines 59209 59209
Branches 4182 4179 -3
=======================================
Hits 33330 33330
Misses 25774 25774
Partials 105 105
🚀 New features to boost your workflow:
|

PR-Codex overview
This PR focuses on enhancing error handling and response structures in payment settlement and verification processes, alongside some refactoring in the codebase for better clarity and functionality.
Detailed summary
errorMessagefield toFacilitatorSettleResponseSchemaandFacilitatorVerifyResponseSchema.settlePaymentandverifyPaymentfunctions.signERC2612Permitto usetoinstead offacilitatorAddress.payToinput from the UI and adjusted related logic.twFacilitatorinstance.Summary by CodeRabbit
New Features
Refactor
Chores