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 any x402 middleware library like x402-hono, x402-next, x402-express, etc.
Then, use the facilitator
configuratino function settle transactions with your thirdweb server wallet gaslessly and pass it to the middleware.
Here's an example with Next.js: