Payment Validation
Payment Validation
After the proxy receives a request with an X-PAYMENT header, it calls the facilitator's /verify endpoint before committing to on-chain settlement.
Verify endpoint
POST https://chainpe-facilitator-production-000a.up.railway.app/verify
Content-Type: application/json
{
"paymentPayload": { ... signed x402 payload ... },
"paymentRequirements": { ... the offer from the 402 response ... }
}What verify checks
The x402 library's verify() function (which ChainPe wraps) performs:
- Schema validation — both payload and requirements pass
PaymentPayloadSchema.parse()andPaymentRequirementsSchema.parse()(Zod schemas) - Version check —
x402Versionmust match - Scheme check —
schememust be"exact" - Network check —
networkmust match the facilitator's configured network - Asset check —
assetmust be the canonical USDC address for the network - Amount check —
valuemust equalmaxAmountRequired - Expiry check —
validBeforemust be in the future - Signature verification — recovers
fromfrom the EIP-3009 signature usingverifyTypedData; the recovered address must matchauthorization.from - Nonce uniqueness — checks that this nonce has not been used for this
fromaddress
Response
{ "isValid": true }Or on failure:
{
"isValid": false,
"invalidReason": "invalid_signature"
}When verify is skipped
The x402-express middleware calls verify then settle in sequence. Some proxy configurations call settle directly (which calls verify internally). In ChainPe's current implementation, the proxy calls settle directly, which calls verify as part of the settlement flow.
On-chain verification (USDC contract)
The final verification happens on-chain when the facilitator calls transferWithAuthorization. The USDC contract independently verifies:
- The EIP-3009 signature (using
ecrecover) - That
fromhas sufficient USDC balance - That
validAfter <= block.timestamp < validBefore - That the nonce has not been used (the USDC contract maintains a bitmap of used authorization nonces)
If any of these fail, the transferWithAuthorization call reverts and the settlement fails. The proxy returns a second 402 to the client in this case, surfaced as a ChainPePaymentError with reason: 'settlement_rejected'.