The fetch function to wrap (typically globalThis.fetch)
Optionalinit: RequestInitOptionalinit: RequestInitConfigured t402Client or t402HTTPClient instance for handling payments
A wrapped fetch function that handles 402 responses automatically
import { wrapFetchWithPayment, t402Client } from '@t402/fetch';
import { ExactEvmScheme } from '@t402/evm';
import { ExactSvmScheme } from '@t402/svm';
const client = new t402Client()
.register('eip155:8453', new ExactEvmScheme(evmSigner))
.register('solana:mainnet', new ExactSvmScheme(svmSigner))
.register('eip155:1', new ExactEvmScheme(evmSigner), 1); // v1 protocol
const fetchWithPay = wrapFetchWithPayment(fetch, client);
// Make a request that may require payment
const response = await fetchWithPay('https://api.example.com/paid-endpoint');
Enables the payment of APIs using the t402 payment protocol v2.
This function wraps the native fetch API to automatically handle 402 Payment Required responses by creating and sending payment headers. It will: