Payments
Server Side
Accept x402 payments in your APIs using any x402-compatible client. Your server can verify and settle payments using thirdweb's facilitator service or any custom facilitator.
The x402 protocol follows this 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
You have two options for handling payments:
Use settlePayment()
to verify and settle the payment in one step. This is the simplest approach:
Use verifyPayment()
first, do the work, then settlePayment()
. This is useful when:
- The final price might be dynamic based on the work performed
- You want to ensure the payment is valid before doing expensive work
- You need to calculate resource usage before charging
Protect individual API endpoints with x402 payments:
Protect multiple endpoints with a shared middleware:
You can specify prices in multiple ways:
Payments in native tokens are not currently supported.