TypeScript SDK
x402.wrapFetchWithPayment
Enables the payment of APIs using the x402 payment protocol.
This function wraps the native fetch API to automatically handle 402 Payment Required responses by creating and sending a payment header. It will:
Make the initial request
If a 402 response is received, parse the payment requirements
Verify the payment amount is within the allowed maximum
Create a payment header using the provided wallet client
Retry the request with the payment header