thirdweb 5.112.4 → 5.114.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. package/dist/cjs/exports/react.js +4 -1
  2. package/dist/cjs/exports/react.js.map +1 -1
  3. package/dist/cjs/exports/react.native.js +4 -1
  4. package/dist/cjs/exports/react.native.js.map +1 -1
  5. package/dist/cjs/react/core/hooks/x402/useFetchWithPaymentCore.js +110 -0
  6. package/dist/cjs/react/core/hooks/x402/useFetchWithPaymentCore.js.map +1 -0
  7. package/dist/cjs/react/native/hooks/x402/useFetchWithPayment.js +89 -0
  8. package/dist/cjs/react/native/hooks/x402/useFetchWithPayment.js.map +1 -0
  9. package/dist/cjs/react/web/hooks/x402/useFetchWithPayment.js +168 -0
  10. package/dist/cjs/react/web/hooks/x402/useFetchWithPayment.js.map +1 -0
  11. package/dist/cjs/react/web/ui/components/basic.js +1 -1
  12. package/dist/cjs/react/web/ui/x402/PaymentErrorModal.js +107 -0
  13. package/dist/cjs/react/web/ui/x402/PaymentErrorModal.js.map +1 -0
  14. package/dist/cjs/react/web/ui/x402/SignInRequiredModal.js +28 -0
  15. package/dist/cjs/react/web/ui/x402/SignInRequiredModal.js.map +1 -0
  16. package/dist/cjs/version.js +1 -1
  17. package/dist/cjs/wallets/coinbase/coinbase-web.js +9 -0
  18. package/dist/cjs/wallets/coinbase/coinbase-web.js.map +1 -1
  19. package/dist/cjs/x402/common.js +2 -10
  20. package/dist/cjs/x402/common.js.map +1 -1
  21. package/dist/cjs/x402/facilitator.js +2 -1
  22. package/dist/cjs/x402/facilitator.js.map +1 -1
  23. package/dist/cjs/x402/fetchWithPayment.js +13 -14
  24. package/dist/cjs/x402/fetchWithPayment.js.map +1 -1
  25. package/dist/cjs/x402/schemas.js +4 -1
  26. package/dist/cjs/x402/schemas.js.map +1 -1
  27. package/dist/cjs/x402/settle-payment.js +13 -2
  28. package/dist/cjs/x402/settle-payment.js.map +1 -1
  29. package/dist/cjs/x402/types.js +6 -1
  30. package/dist/cjs/x402/types.js.map +1 -1
  31. package/dist/cjs/x402/verify-payment.js +12 -2
  32. package/dist/cjs/x402/verify-payment.js.map +1 -1
  33. package/dist/esm/exports/react.js +2 -0
  34. package/dist/esm/exports/react.js.map +1 -1
  35. package/dist/esm/exports/react.native.js +2 -0
  36. package/dist/esm/exports/react.native.js.map +1 -1
  37. package/dist/esm/react/core/hooks/x402/useFetchWithPaymentCore.js +107 -0
  38. package/dist/esm/react/core/hooks/x402/useFetchWithPaymentCore.js.map +1 -0
  39. package/dist/esm/react/native/hooks/x402/useFetchWithPayment.js +86 -0
  40. package/dist/esm/react/native/hooks/x402/useFetchWithPayment.js.map +1 -0
  41. package/dist/esm/react/web/hooks/x402/useFetchWithPayment.js +165 -0
  42. package/dist/esm/react/web/hooks/x402/useFetchWithPayment.js.map +1 -0
  43. package/dist/esm/react/web/ui/components/basic.js +1 -1
  44. package/dist/esm/react/web/ui/x402/PaymentErrorModal.js +104 -0
  45. package/dist/esm/react/web/ui/x402/PaymentErrorModal.js.map +1 -0
  46. package/dist/esm/react/web/ui/x402/SignInRequiredModal.js +25 -0
  47. package/dist/esm/react/web/ui/x402/SignInRequiredModal.js.map +1 -0
  48. package/dist/esm/version.js +1 -1
  49. package/dist/esm/wallets/coinbase/coinbase-web.js +9 -0
  50. package/dist/esm/wallets/coinbase/coinbase-web.js.map +1 -1
  51. package/dist/esm/x402/common.js +2 -10
  52. package/dist/esm/x402/common.js.map +1 -1
  53. package/dist/esm/x402/facilitator.js +2 -1
  54. package/dist/esm/x402/facilitator.js.map +1 -1
  55. package/dist/esm/x402/fetchWithPayment.js +13 -14
  56. package/dist/esm/x402/fetchWithPayment.js.map +1 -1
  57. package/dist/esm/x402/schemas.js +4 -1
  58. package/dist/esm/x402/schemas.js.map +1 -1
  59. package/dist/esm/x402/settle-payment.js +13 -2
  60. package/dist/esm/x402/settle-payment.js.map +1 -1
  61. package/dist/esm/x402/types.js +5 -0
  62. package/dist/esm/x402/types.js.map +1 -1
  63. package/dist/esm/x402/verify-payment.js +12 -2
  64. package/dist/esm/x402/verify-payment.js.map +1 -1
  65. package/dist/scripts/bridge-widget.js +50 -50
  66. package/dist/types/exports/react.d.ts +1 -0
  67. package/dist/types/exports/react.d.ts.map +1 -1
  68. package/dist/types/exports/react.native.d.ts +1 -0
  69. package/dist/types/exports/react.native.d.ts.map +1 -1
  70. package/dist/types/react/core/hooks/x402/useFetchWithPaymentCore.d.ts +131 -0
  71. package/dist/types/react/core/hooks/x402/useFetchWithPaymentCore.d.ts.map +1 -0
  72. package/dist/types/react/native/hooks/x402/useFetchWithPayment.d.ts +189 -0
  73. package/dist/types/react/native/hooks/x402/useFetchWithPayment.d.ts.map +1 -0
  74. package/dist/types/react/web/hooks/x402/useFetchWithPayment.d.ts +248 -0
  75. package/dist/types/react/web/hooks/x402/useFetchWithPayment.d.ts.map +1 -0
  76. package/dist/types/react/web/ui/x402/PaymentErrorModal.d.ts +20 -0
  77. package/dist/types/react/web/ui/x402/PaymentErrorModal.d.ts.map +1 -0
  78. package/dist/types/react/web/ui/x402/SignInRequiredModal.d.ts +12 -0
  79. package/dist/types/react/web/ui/x402/SignInRequiredModal.d.ts.map +1 -0
  80. package/dist/types/version.d.ts +1 -1
  81. package/dist/types/x402/common.d.ts.map +1 -1
  82. package/dist/types/x402/facilitator.d.ts +1 -1
  83. package/dist/types/x402/facilitator.d.ts.map +1 -1
  84. package/dist/types/x402/fetchWithPayment.d.ts +7 -3
  85. package/dist/types/x402/fetchWithPayment.d.ts.map +1 -1
  86. package/dist/types/x402/schemas.d.ts +17 -17
  87. package/dist/types/x402/schemas.d.ts.map +1 -1
  88. package/dist/types/x402/settle-payment.d.ts +13 -2
  89. package/dist/types/x402/settle-payment.d.ts.map +1 -1
  90. package/dist/types/x402/types.d.ts +13 -1
  91. package/dist/types/x402/types.d.ts.map +1 -1
  92. package/dist/types/x402/verify-payment.d.ts +12 -2
  93. package/dist/types/x402/verify-payment.d.ts.map +1 -1
  94. package/package.json +3 -3
  95. package/src/exports/react.native.ts +5 -0
  96. package/src/exports/react.ts +5 -0
  97. package/src/react/core/hooks/x402/useFetchWithPaymentCore.ts +160 -0
  98. package/src/react/native/hooks/x402/useFetchWithPayment.ts +96 -0
  99. package/src/react/web/hooks/x402/useFetchWithPayment.tsx +238 -0
  100. package/src/react/web/ui/components/basic.tsx +1 -1
  101. package/src/react/web/ui/x402/PaymentErrorModal.tsx +261 -0
  102. package/src/react/web/ui/x402/SignInRequiredModal.tsx +75 -0
  103. package/src/version.ts +1 -1
  104. package/src/wallets/coinbase/coinbase-web.ts +10 -0
  105. package/src/x402/common.ts +2 -20
  106. package/src/x402/facilitator.ts +2 -1
  107. package/src/x402/fetchWithPayment.ts +23 -22
  108. package/src/x402/schemas.ts +4 -1
  109. package/src/x402/settle-payment.ts +13 -2
  110. package/src/x402/types.ts +16 -1
  111. package/src/x402/verify-payment.ts +12 -2
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PaymentErrorModal.d.ts","sourceRoot":"","sources":["../../../../../../src/react/web/ui/x402/PaymentErrorModal.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAGL,KAAK,4BAA4B,EAClC,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAEvE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;AAGlE,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAUxE,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EAAE,cAAc,CAAC;IACvB,SAAS,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAC;IACjD,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,KAAK,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;IAChC,iBAAiB,CAAC,EAAE,OAAO,CACzB,IAAI,CACF,cAAc,EACZ,QAAQ,GACR,OAAO,GACP,cAAc,GACd,QAAQ,GACR,WAAW,GACX,UAAU,GACV,OAAO,CACV,CACF,CAAC;IACF,2BAA2B,CAAC,EAAE,CAC5B,mBAAmB,EAAE,4BAA4B,EAAE,KAChD,4BAA4B,GAAG,SAAS,CAAC;CAC/C,CAAC;AAIF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,2CAiL9D"}
@@ -0,0 +1,12 @@
1
+ import type { Theme } from "../../../core/design-system/index.js";
2
+ type SignInRequiredModalProps = {
3
+ theme: Theme | "light" | "dark";
4
+ onSignIn: () => void;
5
+ onCancel: () => void;
6
+ };
7
+ /**
8
+ * @internal
9
+ */
10
+ export declare function SignInRequiredModal(props: SignInRequiredModalProps): import("react/jsx-runtime").JSX.Element;
11
+ export {};
12
+ //# sourceMappingURL=SignInRequiredModal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignInRequiredModal.d.ts","sourceRoot":"","sources":["../../../../../../src/react/web/ui/x402/SignInRequiredModal.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;AAWlE,KAAK,wBAAwB,GAAG;IAC9B,KAAK,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;IAChC,QAAQ,EAAE,MAAM,IAAI,CAAC;IACrB,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,2CAoDlE"}
@@ -1,2 +1,2 @@
1
- export declare const version = "5.112.4";
1
+ export declare const version = "5.114.0";
2
2
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/x402/common.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,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B,EAAE,4BAA4B,CAAC;IAC1D,cAAc,EAAE,uBAAuB,CAAC;CACzC,CAAC;AAEF;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,4BAA4B,GAAG,qBAAqB,CAAC,CA8D/D;AAED,wBAAsB,yBAAyB,CAAC,IAAI,EAAE;IACpD,MAAM,EAAE,cAAc,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,gBAAgB,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,GAAG,SAAS,CAAC;CAC/D,GAAG,OAAO,CAAC,sBAAsB,GAAG,SAAS,CAAC,CAiC9C"}
@@ -82,7 +82,7 @@ export type ThirdwebX402Facilitator = {
82
82
 
83
83
  * ```
84
84
  *
85
- * @bridge x402
85
+ * @x402
86
86
  */
87
87
  export declare function facilitator(config: ThirdwebX402FacilitatorConfig): ThirdwebX402Facilitator;
88
88
  //# sourceMappingURL=facilitator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"facilitator.d.ts","sourceRoot":"","sources":["../../../src/x402/facilitator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG1D,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,KAAK,yBAAyB,EAE9B,KAAK,uBAAuB,EAC5B,KAAK,4BAA4B,EAClC,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAErE,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAEhE,MAAM,MAAM,6BAA6B,GAAG;IAC1C,MAAM,EAAE,cAAc,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;IAC5B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,gBAAgB,CAAC,EA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AAC,yBAAyB,CAAC,CAAC;IACxC,SAAS,EAAE,CAAC,OAAO,CAAC,EAAE;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,YAAY,CAAC,EAAE,MAAM,CAAC;KACvB,KAAK,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAC5C,OAAO,EAAE,CACP,IAAI,EAAE,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,KACnC,OAAO,CAAC,qBAAqB,CAAC,CAAC;CACrC,CAAC;AAIF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqDG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,6BAA6B,GACpC,uBAAuB,CA+LzB"}
@@ -1,5 +1,6 @@
1
1
  import type { ThirdwebClient } from "../client/client.js";
2
2
  import type { Wallet } from "../wallets/interfaces/wallet.js";
3
+ import { type RequestedPaymentRequirements } from "./schemas.js";
3
4
  /**
4
5
  * Enables the payment of APIs using the x402 payment protocol.
5
6
  *
@@ -14,7 +15,7 @@ import type { Wallet } from "../wallets/interfaces/wallet.js";
14
15
  * @param fetch - The fetch function to wrap (typically globalThis.fetch)
15
16
  * @param client - The thirdweb client used to access RPC infrastructure
16
17
  * @param wallet - The wallet used to sign payment messages
17
- * @param maxValue - The maximum allowed payment amount in base units (defaults to 1 USDC)
18
+ * @param maxValue - The maximum allowed payment amount in base units
18
19
  * @returns A wrapped fetch function that handles 402 responses automatically
19
20
  *
20
21
  * @example
@@ -37,7 +38,10 @@ import type { Wallet } from "../wallets/interfaces/wallet.js";
37
38
  * @throws {Error} If a payment has already been attempted for this request
38
39
  * @throws {Error} If there's an error creating the payment header
39
40
  *
40
- * @bridge x402
41
+ * @x402
41
42
  */
42
- export declare function wrapFetchWithPayment(fetch: typeof globalThis.fetch, client: ThirdwebClient, wallet: Wallet, maxValue?: bigint): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
43
+ export declare function wrapFetchWithPayment(fetch: typeof globalThis.fetch, client: ThirdwebClient, wallet: Wallet, options?: {
44
+ maxValue?: bigint;
45
+ paymentRequirementsSelector?: (paymentRequirements: RequestedPaymentRequirements[]) => RequestedPaymentRequirements | undefined;
46
+ }): (input: RequestInfo, init?: RequestInit) => Promise<Response>;
43
47
  //# sourceMappingURL=fetchWithPayment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetchWithPayment.d.ts","sourceRoot":"","sources":["../../../src/x402/fetchWithPayment.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAS9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,IAEH,OAAO,WAAW,EAAE,OAAO,WAAW,uBA4FrD"}
1
+ {"version":3,"file":"fetchWithPayment.d.ts","sourceRoot":"","sources":["../../../src/x402/fetchWithPayment.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAGL,KAAK,4BAA4B,EAElC,MAAM,cAAc,CAAC;AAGtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,UAAU,CAAC,KAAK,EAC9B,MAAM,EAAE,cAAc,EACtB,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2BAA2B,CAAC,EAAE,CAC5B,mBAAmB,EAAE,4BAA4B,EAAE,KAChD,4BAA4B,GAAG,SAAS,CAAC;CAC/C,IAEa,OAAO,WAAW,EAAE,OAAO,WAAW,uBA6FrD"}
@@ -5,7 +5,6 @@ declare const FacilitatorNetworkSchema: z.ZodString;
5
5
  export type FacilitatorNetwork = z.infer<typeof FacilitatorNetworkSchema>;
6
6
  declare const RequestedPaymentPayloadSchema: z.ZodObject<{
7
7
  x402Version: z.ZodEffects<z.ZodNumber, number, number>;
8
- scheme: z.ZodEnum<["exact"]>;
9
8
  payload: z.ZodUnion<[z.ZodObject<{
10
9
  signature: z.ZodString;
11
10
  authorization: z.ZodObject<{
@@ -59,6 +58,7 @@ declare const RequestedPaymentPayloadSchema: z.ZodObject<{
59
58
  }>]>;
60
59
  } & {
61
60
  network: z.ZodString;
61
+ scheme: z.ZodUnion<[z.ZodLiteral<"exact">, z.ZodLiteral<"upto">]>;
62
62
  }, "strip", z.ZodTypeAny, {
63
63
  payload: {
64
64
  signature: string;
@@ -73,7 +73,7 @@ declare const RequestedPaymentPayloadSchema: z.ZodObject<{
73
73
  } | {
74
74
  transaction: string;
75
75
  };
76
- scheme: "exact";
76
+ scheme: "exact" | "upto";
77
77
  network: string;
78
78
  x402Version: number;
79
79
  }, {
@@ -90,7 +90,7 @@ declare const RequestedPaymentPayloadSchema: z.ZodObject<{
90
90
  } | {
91
91
  transaction: string;
92
92
  };
93
- scheme: "exact";
93
+ scheme: "exact" | "upto";
94
94
  network: string;
95
95
  x402Version: number;
96
96
  }>;
@@ -101,7 +101,6 @@ export type UnsignedPaymentPayload = Omit<RequestedPaymentPayload, "payload"> &
101
101
  };
102
102
  };
103
103
  export declare const RequestedPaymentRequirementsSchema: z.ZodObject<{
104
- scheme: z.ZodEnum<["exact"]>;
105
104
  maxAmountRequired: z.ZodEffects<z.ZodString, string, string>;
106
105
  resource: z.ZodString;
107
106
  description: z.ZodString;
@@ -113,28 +112,29 @@ export declare const RequestedPaymentRequirementsSchema: z.ZodObject<{
113
112
  extra: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
114
113
  } & {
115
114
  network: z.ZodString;
115
+ scheme: z.ZodUnion<[z.ZodLiteral<"exact">, z.ZodLiteral<"upto">]>;
116
116
  }, "strip", z.ZodTypeAny, {
117
117
  description: string;
118
- scheme: "exact";
118
+ scheme: "exact" | "upto";
119
119
  resource: string;
120
120
  mimeType: string;
121
- asset: string;
122
121
  network: string;
123
122
  maxAmountRequired: string;
124
123
  payTo: string;
125
124
  maxTimeoutSeconds: number;
125
+ asset: string;
126
126
  outputSchema?: Record<string, any> | undefined;
127
127
  extra?: Record<string, any> | undefined;
128
128
  }, {
129
129
  description: string;
130
- scheme: "exact";
130
+ scheme: "exact" | "upto";
131
131
  resource: string;
132
132
  mimeType: string;
133
- asset: string;
134
133
  network: string;
135
134
  maxAmountRequired: string;
136
135
  payTo: string;
137
136
  maxTimeoutSeconds: number;
137
+ asset: string;
138
138
  outputSchema?: Record<string, any> | undefined;
139
139
  extra?: Record<string, any> | undefined;
140
140
  }>;
@@ -154,16 +154,16 @@ declare const FacilitatorSettleResponseSchema: z.ZodObject<{
154
154
  network: string;
155
155
  errorMessage?: string | undefined;
156
156
  fundWalletLink?: string | undefined;
157
- errorReason?: "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
158
157
  payer?: string | undefined;
158
+ errorReason?: "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
159
159
  }, {
160
160
  transaction: string;
161
161
  success: boolean;
162
162
  network: string;
163
163
  errorMessage?: string | undefined;
164
164
  fundWalletLink?: string | undefined;
165
- errorReason?: "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
166
165
  payer?: string | undefined;
166
+ errorReason?: "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
167
167
  }>;
168
168
  export type FacilitatorSettleResponse = z.infer<typeof FacilitatorSettleResponseSchema>;
169
169
  declare const FacilitatorVerifyResponseSchema: z.ZodObject<{
@@ -177,21 +177,21 @@ declare const FacilitatorVerifyResponseSchema: z.ZodObject<{
177
177
  isValid: boolean;
178
178
  errorMessage?: string | undefined;
179
179
  fundWalletLink?: string | undefined;
180
- payer?: string | undefined;
181
180
  invalidReason?: "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
181
+ payer?: string | undefined;
182
182
  }, {
183
183
  isValid: boolean;
184
184
  errorMessage?: string | undefined;
185
185
  fundWalletLink?: string | undefined;
186
- payer?: string | undefined;
187
186
  invalidReason?: "insufficient_funds" | "invalid_exact_evm_payload_authorization_valid_after" | "invalid_exact_evm_payload_authorization_valid_before" | "invalid_exact_evm_payload_authorization_value" | "invalid_exact_evm_payload_signature" | "invalid_exact_evm_payload_recipient_mismatch" | "invalid_exact_svm_payload_transaction" | "invalid_exact_svm_payload_transaction_amount_mismatch" | "invalid_exact_svm_payload_transaction_create_ata_instruction" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_payee" | "invalid_exact_svm_payload_transaction_create_ata_instruction_incorrect_asset" | "invalid_exact_svm_payload_transaction_instructions" | "invalid_exact_svm_payload_transaction_instructions_length" | "invalid_exact_svm_payload_transaction_instructions_compute_limit_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction" | "invalid_exact_svm_payload_transaction_instructions_compute_price_instruction_too_high" | "invalid_exact_svm_payload_transaction_instruction_not_spl_token_transfer_checked" | "invalid_exact_svm_payload_transaction_instruction_not_token_2022_transfer_checked" | "invalid_exact_svm_payload_transaction_not_a_transfer_instruction" | "invalid_exact_svm_payload_transaction_receiver_ata_not_found" | "invalid_exact_svm_payload_transaction_sender_ata_not_found" | "invalid_exact_svm_payload_transaction_simulation_failed" | "invalid_exact_svm_payload_transaction_transfer_to_incorrect_ata" | "invalid_network" | "invalid_payload" | "invalid_payment_requirements" | "invalid_scheme" | "invalid_payment" | "payment_expired" | "unsupported_scheme" | "invalid_x402_version" | "invalid_transaction_state" | "settle_exact_svm_block_height_exceeded" | "settle_exact_svm_transaction_confirmation_timed_out" | "unexpected_settle_error" | "unexpected_verify_error" | undefined;
187
+ payer?: string | undefined;
188
188
  }>;
189
189
  export type FacilitatorVerifyResponse = z.infer<typeof FacilitatorVerifyResponseSchema>;
190
190
  export declare const SupportedSignatureTypeSchema: z.ZodEnum<["TransferWithAuthorization", "Permit"]>;
191
191
  declare const FacilitatorSupportedResponseSchema: z.ZodObject<{} & {
192
192
  kinds: z.ZodArray<z.ZodObject<{
193
193
  x402Version: z.ZodLiteral<1>;
194
- scheme: z.ZodLiteral<"exact">;
194
+ scheme: z.ZodUnion<[z.ZodLiteral<"exact">, z.ZodLiteral<"upto">]>;
195
195
  network: z.ZodString;
196
196
  extra: z.ZodOptional<z.ZodObject<{
197
197
  defaultAsset: z.ZodOptional<z.ZodObject<{
@@ -300,7 +300,7 @@ declare const FacilitatorSupportedResponseSchema: z.ZodObject<{} & {
300
300
  }[] | undefined;
301
301
  }>>;
302
302
  }, "strip", z.ZodTypeAny, {
303
- scheme: "exact";
303
+ scheme: "exact" | "upto";
304
304
  network: string;
305
305
  x402Version: 1;
306
306
  extra?: {
@@ -324,7 +324,7 @@ declare const FacilitatorSupportedResponseSchema: z.ZodObject<{} & {
324
324
  }[] | undefined;
325
325
  } | undefined;
326
326
  }, {
327
- scheme: "exact";
327
+ scheme: "exact" | "upto";
328
328
  network: string;
329
329
  x402Version: 1;
330
330
  extra?: {
@@ -350,7 +350,7 @@ declare const FacilitatorSupportedResponseSchema: z.ZodObject<{} & {
350
350
  }>, "many">;
351
351
  }, "strip", z.ZodTypeAny, {
352
352
  kinds: {
353
- scheme: "exact";
353
+ scheme: "exact" | "upto";
354
354
  network: string;
355
355
  x402Version: 1;
356
356
  extra?: {
@@ -376,7 +376,7 @@ declare const FacilitatorSupportedResponseSchema: z.ZodObject<{} & {
376
376
  }[];
377
377
  }, {
378
378
  kinds: {
379
- scheme: "exact";
379
+ scheme: "exact" | "upto";
380
380
  network: string;
381
381
  x402Version: 1;
382
382
  extra?: {
@@ -1 +1 @@
1
- {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../src/x402/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EAOrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,QAAA,MAAM,wBAAwB,aAAa,CAAC;AAE5C,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB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;;;EAI3C,CAAC;AAEL,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAChD,OAAO,kCAAkC,CAC1C,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;EAInC,CAAC;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,+BAA+B,CACvC,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;EAGnC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,+BAA+B,CACvC,CAAC;AAEF,eAAO,MAAM,4BAA4B,oDAGvC,CAAC;AAYH,QAAA,MAAM,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAiBqB,CAAC;AAE9D,MAAM,MAAM,4BAA4B,GAAG,CAAC,CAAC,KAAK,CAChD,OAAO,kCAAkC,CAC1C,CAAC;AAMF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,YAAY,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAO3E;AAED;;;GAGG;AACH,QAAA,MAAM,kBAAkB,8FA8DrB,CAAC;AAEJ,KAAK,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAExD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,GAAG,YAAY,CAK3E"}
@@ -43,7 +43,6 @@ import { type SettlePaymentArgs, type SettlePaymentResult } from "./types.js";
43
43
  * routeConfig: {
44
44
  * description: "Access to premium API content",
45
45
  * mimeType: "application/json",
46
- * maxTimeoutSeconds: 300,
47
46
  * },
48
47
  * });
49
48
  *
@@ -60,6 +59,18 @@ import { type SettlePaymentArgs, type SettlePaymentResult } from "./types.js";
60
59
  * }
61
60
  * ```
62
61
  *
62
+ * ### Upto Payment Scheme
63
+ *
64
+ * You can also use the `upto` payment scheme to settle the payment dynamically based on the usage.
65
+ *
66
+ * ```ts
67
+ * const result = await settlePayment({
68
+ * ...paymentArgs,
69
+ * scheme: "upto",
70
+ * price: "$0.10", // max payable amount
71
+ * });
72
+ * ```
73
+ *
63
74
  * ### Express middleware example
64
75
  *
65
76
  * ```ts
@@ -114,7 +125,7 @@ import { type SettlePaymentArgs, type SettlePaymentResult } from "./types.js";
114
125
  *
115
126
  * @public
116
127
  * @beta
117
- * @bridge x402
128
+ * @x402
118
129
  */
119
130
  export declare function settlePayment(args: SettlePaymentArgs): Promise<SettlePaymentResult>;
120
131
  //# sourceMappingURL=settle-payment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"settle-payment.d.ts","sourceRoot":"","sources":["../../../src/x402/settle-payment.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoHG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,mBAAmB,CAAC,CA8D9B"}
1
+ {"version":3,"file":"settle-payment.d.ts","sourceRoot":"","sources":["../../../src/x402/settle-payment.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+HG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,mBAAmB,CAAC,CA8D9B"}
@@ -1,5 +1,5 @@
1
1
  import type { Money, PaymentMiddlewareConfig } from "x402/types";
2
- import type z from "zod";
2
+ import z from "zod";
3
3
  import type { Chain } from "../chains/types.js";
4
4
  import type { Prettify } from "../utils/type-utils.js";
5
5
  import type { ThirdwebX402Facilitator, WaitUntil } from "./facilitator.js";
@@ -23,6 +23,8 @@ export type PaymentArgs = {
23
23
  price: Money | ERC20TokenAmount;
24
24
  /** The payment facilitator instance used to verify and settle payments */
25
25
  facilitator: ThirdwebX402Facilitator;
26
+ /** The scheme of the payment, either "exact" or "upto", defaults to "exact" */
27
+ scheme?: PaymentScheme;
26
28
  /** Optional configuration for the payment middleware route */
27
29
  routeConfig?: PaymentMiddlewareConfig;
28
30
  /** Optional recipient address to receive the payment if different from your facilitator address */
@@ -75,12 +77,21 @@ export type SettlePaymentResult = Prettify<{
75
77
  export type VerifyPaymentResult = Prettify<{
76
78
  /** HTTP 200 - Payment was successfully verified */
77
79
  status: 200;
80
+ /** The decoded payment payload */
78
81
  decodedPayment: RequestedPaymentPayload;
82
+ /** The selected payment requirements */
79
83
  selectedPaymentRequirements: RequestedPaymentRequirements;
80
84
  } | PaymentRequiredResult>;
81
85
  export type SupportedSignatureType = z.infer<typeof SupportedSignatureTypeSchema>;
86
+ export declare const PaymentSchemeSchema: z.ZodUnion<[z.ZodLiteral<"exact">, z.ZodLiteral<"upto">]>;
87
+ type PaymentScheme = z.infer<typeof PaymentSchemeSchema>;
88
+ /**
89
+ * The asset, scheme and amount for the payment in base units
90
+ */
82
91
  export type ERC20TokenAmount = {
92
+ /** The amount of the payment in base units */
83
93
  amount: string;
94
+ /** The asset of the payment, decimals and eip712 data are optional and will be inferred from the address if not provided */
84
95
  asset: {
85
96
  address: `0x${string}`;
86
97
  decimals?: number;
@@ -91,4 +102,5 @@ export type ERC20TokenAmount = {
91
102
  };
92
103
  };
93
104
  };
105
+ export {};
94
106
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/x402/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AACvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EACV,kBAAkB,EAClB,yBAAyB,EACzB,uBAAuB,EACvB,4BAA4B,EAC5B,4BAA4B,EAC7B,MAAM,cAAc,CAAC;AAEtB,eAAO,MAAM,WAAW,IAAI,CAAC;AAE7B;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,6DAA6D;IAC7D,WAAW,EAAE,MAAM,CAAC;IACpB,kDAAkD;IAClD,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,CAAC,EAAE,GAAG,MAAM,CAAC,CAAC;IACvC,yFAAyF;IACzF,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,mEAAmE;IACnE,OAAO,EAAE,kBAAkB,GAAG,KAAK,CAAC;IACpC,4GAA4G;IAC5G,KAAK,EAAE,KAAK,GAAG,gBAAgB,CAAC;IAChC,0EAA0E;IAC1E,WAAW,EAAE,uBAAuB,CAAC;IACrC,8DAA8D;IAC9D,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACtC,mGAAmG;IACnG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,aAAa,CAAC,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xC,wCAAwC;IACxC,2BAA2B,EAAE,4BAA4B,CAAC;CAC3D,GACD,qBAAqB,CACxB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAC1C,OAAO,4BAA4B,CACpC,CAAC;AAEF,eAAO,MAAM,mBAAmB,2DAG9B,CAAC;AACH,KAAK,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEzD;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,8CAA8C;IAC9C,MAAM,EAAE,MAAM,CAAC;IACf,4HAA4H;IAC5H,KAAK,EAAE;QACL,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE;YACP,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,EAAE,MAAM,CAAC;YAChB,WAAW,EAAE,sBAAsB,CAAC;SACrC,CAAC;KACH,CAAC;CACH,CAAC"}
@@ -36,7 +36,6 @@ import { type PaymentArgs, type VerifyPaymentResult } from "./types.js";
36
36
  * routeConfig: {
37
37
  * description: "Access to premium API content",
38
38
  * mimeType: "application/json",
39
- * maxTimeoutSeconds: 300,
40
39
  * },
41
40
  * };
42
41
  *
@@ -62,9 +61,20 @@ import { type PaymentArgs, type VerifyPaymentResult } from "./types.js";
62
61
  * }
63
62
  * ```
64
63
  *
64
+ * ### Upto Payment Scheme
65
+ *
66
+ * You can also use the `upto` payment scheme to verify a payment where the final price is dynamically calculated based on the usage.
67
+ *
68
+ * ```ts
69
+ * const result = await verifyPayment({
70
+ * ...paymentArgs,
71
+ * scheme: "upto",
72
+ * price: "$0.10", // max payable amount
73
+ * });
74
+ * ```
65
75
  * @public
66
76
  * @beta
67
- * @bridge x402
77
+ * @x402
68
78
  */
69
79
  export declare function verifyPayment(args: PaymentArgs): Promise<VerifyPaymentResult>;
70
80
  //# sourceMappingURL=verify-payment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"verify-payment.d.ts","sourceRoot":"","sources":["../../../src/x402/verify-payment.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,mBAAmB,CAAC,CA2D9B"}
1
+ {"version":3,"file":"verify-payment.d.ts","sourceRoot":"","sources":["../../../src/x402/verify-payment.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EAEzB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,WAAW,GAChB,OAAO,CAAC,mBAAmB,CAAC,CA2D9B"}
package/package.json CHANGED
@@ -39,8 +39,8 @@
39
39
  "viem": "2.39.0",
40
40
  "x402": "0.7.0",
41
41
  "zod": "3.25.75",
42
- "@thirdweb-dev/engine": "3.4.0",
43
- "@thirdweb-dev/insight": "1.1.1"
42
+ "@thirdweb-dev/insight": "1.1.1",
43
+ "@thirdweb-dev/engine": "3.4.0"
44
44
  },
45
45
  "devDependencies": {
46
46
  "@aws-sdk/client-kms": "3.592.0",
@@ -399,7 +399,7 @@
399
399
  }
400
400
  },
401
401
  "typings": "./dist/types/exports/thirdweb.d.ts",
402
- "version": "5.112.4",
402
+ "version": "5.114.0",
403
403
  "scripts": {
404
404
  "bench": "vitest -c ./test/vitest.config.ts bench",
405
405
  "bench:compare": "bun run ./benchmarks/run.ts",
@@ -114,6 +114,11 @@ export { useAutoConnect } from "../react/native/hooks/wallets/useAutoConnect.js"
114
114
  export { useLinkProfile } from "../react/native/hooks/wallets/useLinkProfile.js";
115
115
  export { useProfiles } from "../react/native/hooks/wallets/useProfiles.js";
116
116
  export { useUnlinkProfile } from "../react/native/hooks/wallets/useUnlinkProfile.js";
117
+ // x402
118
+ export {
119
+ type UseFetchWithPaymentOptions,
120
+ useFetchWithPayment,
121
+ } from "../react/native/hooks/x402/useFetchWithPayment.js";
117
122
  export { ThirdwebProvider } from "../react/native/providers/thirdweb-provider.js";
118
123
  // Components
119
124
  export { AutoConnect } from "../react/native/ui/AutoConnect/AutoConnect.js";
@@ -131,6 +131,11 @@ export { useAutoConnect } from "../react/web/hooks/wallets/useAutoConnect.js";
131
131
  export { useLinkProfile } from "../react/web/hooks/wallets/useLinkProfile.js";
132
132
  export { useProfiles } from "../react/web/hooks/wallets/useProfiles.js";
133
133
  export { useUnlinkProfile } from "../react/web/hooks/wallets/useUnlinkProfile.js";
134
+ // x402
135
+ export {
136
+ type UseFetchWithPaymentOptions,
137
+ useFetchWithPayment,
138
+ } from "../react/web/hooks/x402/useFetchWithPayment.js";
134
139
  export { ThirdwebProvider } from "../react/web/providers/thirdweb-provider.js";
135
140
  export { AutoConnect } from "../react/web/ui/AutoConnect/AutoConnect.js";
136
141
  export type { BuyOrOnrampPrepareResult } from "../react/web/ui/Bridge/BuyWidget.js";
@@ -0,0 +1,160 @@
1
+ "use client";
2
+
3
+ import { useMutation } from "@tanstack/react-query";
4
+ import type { ThirdwebClient } from "../../../../client/client.js";
5
+ import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
6
+ import { wrapFetchWithPayment } from "../../../../x402/fetchWithPayment.js";
7
+ import type { RequestedPaymentRequirements } from "../../../../x402/schemas.js";
8
+ import type { PaymentRequiredResult } from "../../../../x402/types.js";
9
+ import { useActiveWallet } from "../wallets/useActiveWallet.js";
10
+
11
+ export type UseFetchWithPaymentOptions = {
12
+ maxValue?: bigint;
13
+ paymentRequirementsSelector?: (
14
+ paymentRequirements: RequestedPaymentRequirements[],
15
+ ) => RequestedPaymentRequirements | undefined;
16
+ parseAs?: "json" | "text" | "raw";
17
+ };
18
+
19
+ type ShowErrorModalCallback = (data: {
20
+ errorData: PaymentRequiredResult["responseBody"];
21
+ onRetry: () => void;
22
+ onCancel: () => void;
23
+ }) => void;
24
+
25
+ type ShowConnectModalCallback = (data: {
26
+ onConnect: (wallet: Wallet) => void;
27
+ onCancel: () => void;
28
+ }) => void;
29
+
30
+ /**
31
+ * Core hook for fetch with payment functionality.
32
+ * This is the platform-agnostic implementation used by both web and native versions.
33
+ * @internal
34
+ */
35
+ export function useFetchWithPaymentCore(
36
+ client: ThirdwebClient,
37
+ options?: UseFetchWithPaymentOptions,
38
+ showErrorModal?: ShowErrorModalCallback,
39
+ showConnectModal?: ShowConnectModalCallback,
40
+ ) {
41
+ const wallet = useActiveWallet();
42
+
43
+ const mutation = useMutation({
44
+ mutationFn: async ({
45
+ input,
46
+ init,
47
+ }: {
48
+ input: RequestInfo;
49
+ init?: RequestInit;
50
+ }) => {
51
+ // Recursive function that handles fetch + 402 error + retry
52
+ const executeFetch = async (currentWallet = wallet): Promise<unknown> => {
53
+ if (!currentWallet) {
54
+ // If a connect modal handler is provided, show the connect modal
55
+ if (showConnectModal) {
56
+ return new Promise<unknown>((resolve, reject) => {
57
+ showConnectModal({
58
+ onConnect: async (newWallet) => {
59
+ // After connection, retry the fetch with the newly connected wallet
60
+ try {
61
+ const result = await executeFetch(newWallet);
62
+ resolve(result);
63
+ } catch (error) {
64
+ reject(error);
65
+ }
66
+ },
67
+ onCancel: () => {
68
+ reject(new Error("Wallet connection cancelled by user"));
69
+ },
70
+ });
71
+ });
72
+ }
73
+
74
+ // If no connect modal handler, throw an error
75
+ throw new Error(
76
+ "No wallet connected. Please connect your wallet to make paid API calls.",
77
+ );
78
+ }
79
+
80
+ const wrappedFetch = wrapFetchWithPayment(
81
+ globalThis.fetch,
82
+ client,
83
+ currentWallet,
84
+ options,
85
+ );
86
+
87
+ const response = await wrappedFetch(input, init);
88
+
89
+ // Check if we got a 402 response (payment error)
90
+ if (response.status === 402) {
91
+ try {
92
+ const errorBody =
93
+ (await response.json()) as PaymentRequiredResult["responseBody"];
94
+
95
+ // If a modal handler is provided, show the modal and handle retry/cancel
96
+ if (showErrorModal) {
97
+ return new Promise<unknown>((resolve, reject) => {
98
+ showErrorModal({
99
+ errorData: errorBody,
100
+ onRetry: async () => {
101
+ // Retry the entire fetch+error handling logic recursively
102
+ try {
103
+ const result = await executeFetch();
104
+ resolve(result);
105
+ } catch (error) {
106
+ reject(error);
107
+ }
108
+ },
109
+ onCancel: () => {
110
+ reject(new Error("Payment cancelled by user"));
111
+ },
112
+ });
113
+ });
114
+ }
115
+
116
+ // If no modal handler, throw the error with details
117
+ throw new Error(
118
+ errorBody.errorMessage || `Payment failed: ${errorBody.error}`,
119
+ );
120
+ } catch (_parseError) {
121
+ // If we can't parse the error body, throw a generic error
122
+ throw new Error("Payment failed with status 402");
123
+ }
124
+ }
125
+
126
+ if (!response.ok) {
127
+ const errorText = await response.text();
128
+ throw new Error(
129
+ `Payment failed with status ${response.status} ${response.statusText} - ${errorText || "Unknown error"}`,
130
+ );
131
+ }
132
+
133
+ const parseAs = options?.parseAs ?? "json";
134
+ return parseResponse(response, parseAs);
135
+ };
136
+
137
+ // Start the fetch process
138
+ return executeFetch();
139
+ },
140
+ });
141
+
142
+ return {
143
+ fetchWithPayment: async (input: RequestInfo, init?: RequestInit) => {
144
+ return mutation.mutateAsync({ input, init });
145
+ },
146
+ ...mutation,
147
+ };
148
+ }
149
+
150
+ function parseResponse(response: Response, parseAs: "json" | "text" | "raw") {
151
+ if (parseAs === "json") {
152
+ return response.json();
153
+ } else if (parseAs === "text") {
154
+ return response.text();
155
+ } else if (parseAs === "raw") {
156
+ return response;
157
+ } else {
158
+ throw new Error(`Invalid parseAs option: ${parseAs}`);
159
+ }
160
+ }