Fetch API wrapper with automatic x402 payment handling
fetch
API to automatically handle 402 Payment Required responses using the x402 payment protocol. This package enables seamless integration of payment functionality into your applications when making HTTP requests.
wrapFetchWithPayment(fetch, walletClient, maxValue?, paymentRequirementsSelector?)
fetch
: The fetch function to wrap (typically globalThis.fetch
)walletClient
: The wallet client used to sign payment messages (must implement the x402 wallet interface)maxValue
: Optional maximum allowed payment amount in base units (defaults to 0.1 USDC)paymentRequirementsSelector
: Optional function to select payment requirements from the response (defaults to selectPaymentRequirements
)