Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/famous-owls-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"thirdweb": patch
---

Make maxAmount optional in wrapFetchWithPayment and loosen schema validation for payment payloads
8 changes: 2 additions & 6 deletions packages/thirdweb/src/x402/encode.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { ExactEvmPayload } from "x402/types";
import {
type RequestedPaymentPayload,
RequestedPaymentPayloadSchema,
} from "./schemas.js";
import type { RequestedPaymentPayload } from "./schemas.js";

/**
* Encodes a payment payload into a base64 string, ensuring bigint values are properly stringified
Expand Down Expand Up @@ -44,8 +41,7 @@ export function decodePayment(payment: string): RequestedPaymentPayload {
...parsed,
payload: parsed.payload as ExactEvmPayload,
};
const validated = RequestedPaymentPayloadSchema.parse(obj);
return validated;
return obj;
}

/**
Expand Down
7 changes: 5 additions & 2 deletions packages/thirdweb/src/x402/fetchWithPayment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function wrapFetchWithPayment(
fetch: typeof globalThis.fetch,
client: ThirdwebClient,
wallet: Wallet,
maxValue: bigint = BigInt(1 * 10 ** 6), // Default to 1 USDC
maxValue?: bigint,
) {
return async (input: RequestInfo, init?: RequestInit) => {
const response = await fetch(input, init);
Expand Down Expand Up @@ -91,7 +91,10 @@ export function wrapFetchWithPayment(
);
}

if (BigInt(selectedPaymentRequirements.maxAmountRequired) > maxValue) {
if (
maxValue &&
BigInt(selectedPaymentRequirements.maxAmountRequired) > maxValue
) {
throw new Error(
`Payment amount exceeds maximum allowed (currently set to ${maxValue} in base units)`,
);
Expand Down
2 changes: 1 addition & 1 deletion packages/thirdweb/src/x402/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const FacilitatorNetworkSchema = z.string();

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

export const RequestedPaymentPayloadSchema = PaymentPayloadSchema.extend({
const RequestedPaymentPayloadSchema = PaymentPayloadSchema.extend({
network: FacilitatorNetworkSchema,
});

Expand Down
Loading