x402 Payment Flow
Step-by-step walkthrough of a complete x402 payment through Zeny.
Step 1: Initial Request
GET /api/premium-data HTTP/1.1
Host: api.example.comStep 2: 402 Response
HTTP/1.1 402 Payment Required
Payment-Required: base64({
"x402Version": "2.0",
"message": "Payment required",
"accepts": [{
"scheme": "exact",
"network": "megaeth",
"amount": "10000",
"asset": "0xfafddbb3...USDM",
"payTo": "0xSeller...",
"facilitator": "https://zeny.cash"
}]
})Step 3: Agent Creates Payment
The agent reads the requirements, creates a Permit2 authorization (EIP-712 typed data), and signs it with its wallet.
Step 4: Retry with Payment
GET /api/premium-data HTTP/1.1
Host: api.example.com
Payment-Signature: base64({
"x402Version": "2.0",
"scheme": "exact",
"network": "megaeth",
"payload": {
"signature": "0xABCD...",
"authorization": {
"from": "0xAgent...",
"to": "0xSeller...",
"value": "10000",
"validAfter": 1700000000,
"validBefore": 1700003600,
"nonce": 1
}
}
})Step 5: Zeny Verifies
The server forwards the payload to Zeny's facilitator:
- Validates signature cryptographically
- Checks USDM balance on MegaETH
- Verifies amount, recipient, and time window
Step 6: Settlement
Zeny submits the Permit2 transfer on MegaETH. Settlement takes ~10ms.
Step 7: Resource Delivered
HTTP/1.1 200 OK
Content-Type: application/json
{ "data": "premium content here" }