Native internet payments on Peaq with x402

x402 is an open-source protocol that turns the dormant HTTP 402 Payment Required status code into a fully-featured, on-chain payment layer for APIs, websites, and autonomous agents.
Learn how to implement x402 on Peaq using the thirdweb SDK.
1. Client side: handle x402 user payments with any wallet
Make requests to any x402-compatible backend by automatically handling payment flows when APIs return a 402 Payment Required
response.
The client library wraps the native fetch
API and handles:
- Initial request to the API
- Detection of
402 Payment Required
responses - Parsing payment requirements from the response
- Creating and signing payment authorization
- Retrying the request with payment credentials

View the full documentation to learn more.
2. Server side: Gate any API call with x402 payments
On your backend, you can gate any API with payment on Peaq using the settlePayment()
function.
This single function handles the full x402 flow:
- Client Request - Client makes a request to your API
- Payment Required - Server responds with 402 and payment requirements
- Client Signs - Client signs payment authorization
- Paid Request - Client retries with payment header
- Verify & Settle - Server verifies and settles the payment
- Success - Server returns the protected content
Here’s an example with a Next.js route:

View the full documentation to learn more.
Additional Resources:
Happy building! 🛠️