Payments
x402 payments
Implement paid API calls using the x402 protocol. Every request is paid for by the user with a micro payment onchain.
x402 Playground
Try out a x402 payment in our live playground
wrapFetchWithPayment
wraps the native fetch API to automatically handle 402 Payment Required
responses from any API call. 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
- Sign a payment authorization
- Create a payment header using the provided wallet signature
- Retry the request with the payment header
Here's an example:
To make your API calls payable, you can use the verifyPayment
function in a simple middleware or in your endpoint directly.
Use the facilitator
configuration function settle transactions with your thirdweb server wallet gaslessly and pass it to the verifyPayment
function.
Here's an example with a Next.js middleware: