10 min
Understanding the x402 Flow (Server Perspective)
Learning Objectives
- Understand the server's role in x402
- Learn what payment details to include in 402 responses
- Understand payment verification
- Recognize security considerations
The Server's Job
As a server implementing x402, your job is to:
1.Require payment for protected endpoints
2.Verify payment proof when provided
3.Only serve data after successful verification
This ensures you get paid for every API call.
The x402 Flow from Server Perspective
1.Client requests your API
2.You check for payment header
3.No payment? → Respond with 402 and payment details
4.Has payment? → Verify signature and settlement
5.Valid payment? → Serve the data
6.Invalid payment? → Respond with 402 again
json
{
"to": "0xYourWalletAddress",
"amount": "0.001",
"network": "base",
"facilitator": "https://facilitator.coinbase.com"
}Security Note: Always verify payments on-chain or via a trusted facilitator. Never trust client-provided payment claims alone.
Knowledge Check
When should you return a 402 response?