Skip to main content

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 → settle all-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

Optional (on demand):

Quick start

Minimal usage (manual handling)

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 body
  • getCacheStats/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 requirements for fixed-price endpoints
  • Background initialization: don’t block startup; log once ready
Performance reference:

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