Skip to content

Commit 7da16cf

Browse files
[SDK] Make maxAmount optional in wrapFetchWithPayment (#8369)
1 parent f0edc0f commit 7da16cf

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

.changeset/famous-owls-lick.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Make maxAmount optional in wrapFetchWithPayment and loosen schema validation for payment payloads

packages/thirdweb/src/x402/encode.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { ExactEvmPayload } from "x402/types";
2-
import {
3-
type RequestedPaymentPayload,
4-
RequestedPaymentPayloadSchema,
5-
} from "./schemas.js";
2+
import type { RequestedPaymentPayload } from "./schemas.js";
63

74
/**
85
* Encodes a payment payload into a base64 string, ensuring bigint values are properly stringified
@@ -44,8 +41,7 @@ export function decodePayment(payment: string): RequestedPaymentPayload {
4441
...parsed,
4542
payload: parsed.payload as ExactEvmPayload,
4643
};
47-
const validated = RequestedPaymentPayloadSchema.parse(obj);
48-
return validated;
44+
return obj;
4945
}
5046

5147
/**

packages/thirdweb/src/x402/fetchWithPayment.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function wrapFetchWithPayment(
5252
fetch: typeof globalThis.fetch,
5353
client: ThirdwebClient,
5454
wallet: Wallet,
55-
maxValue: bigint = BigInt(1 * 10 ** 6), // Default to 1 USDC
55+
maxValue?: bigint,
5656
) {
5757
return async (input: RequestInfo, init?: RequestInit) => {
5858
const response = await fetch(input, init);
@@ -91,7 +91,10 @@ export function wrapFetchWithPayment(
9191
);
9292
}
9393

94-
if (BigInt(selectedPaymentRequirements.maxAmountRequired) > maxValue) {
94+
if (
95+
maxValue &&
96+
BigInt(selectedPaymentRequirements.maxAmountRequired) > maxValue
97+
) {
9598
throw new Error(
9699
`Payment amount exceeds maximum allowed (currently set to ${maxValue} in base units)`,
97100
);

packages/thirdweb/src/x402/schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const FacilitatorNetworkSchema = z.string();
1515

1616
export type FacilitatorNetwork = z.infer<typeof FacilitatorNetworkSchema>;
1717

18-
export const RequestedPaymentPayloadSchema = PaymentPayloadSchema.extend({
18+
const RequestedPaymentPayloadSchema = PaymentPayloadSchema.extend({
1919
network: FacilitatorNetworkSchema,
2020
});
2121

0 commit comments

Comments
 (0)