Overview
x402x-server is the server-side SDK that integrates token detection, payment verification, and settlement to complete the full x402x flow end-to-end: “create payment requirements → parse/verify/settle → return resource.”
Key features
- Simple API: two-argument starting point, handles complexity automatically
- Automatic token detection: powered by
x402x-detector, with built-in cache - Complete payment pipeline:
parse → verify → settleall-in-one - Dynamic requirements creation: supports both fixed and dynamic pricing
- Performance: warm-up cache, fast mode, non-blocking initialization
- Framework middleware: Express / Hono out of the box
- Type-safety: 100% TypeScript + Zod runtime validation
Install and deps
Quick start
Minimal usage (manual handling)
Express middleware (recommended)
Hono middleware
Core capabilities
1) Automatic token detection
2) All-in-one: parse → verify → settle
3) Config and utilities
Utilities
initialize(tokens): warm up detector cache (cache hits in<1ms)get402Response(reqs, message?): build standard 402 response bodygetCacheStats/clearCache: inspect/clear cache
API reference (condensed)
Performance and optimization
- Warm up cache:
initialize([tokens])at service startup - Fast mode:
createRequirements({ paymentType: "permit", autoDetect: false })(<1ms) - Reuse requirements: reuse the same
requirementsfor fixed-price endpoints - Background initialization: don’t block startup; log once ready
| Operation | First call | Cached call |
|---|---|---|
createRequirements(autoDetect: true) | 2–5s | <1ms |
createRequirements(autoDetect: false) | <1ms | <1ms |
process() | 2–5s + network | <1ms + network |
Best practices
- Use env vars for
recipientAddress, RPC, etc. - Distinguish error stages:
parse/verify→ 402;settle→ 500 - Record on-chain tx hash; build reconciliation and retry mechanisms
- Centralize logs and metrics for observability and tuning
Resources
- Source:
https://github.com/WTFLabs-WTF/x402x/tree/main/typescript/packages/x402x-server - Issues:
https://github.com/WTFLabs-WTF/x402x/issues