Start here: need to register a service and create a plan first? Follow the
5-minute setup.
paymentMiddleware handles verification and settlement automatically.
Installation
Quick Start: One-Line Payment Protection
ThepaymentMiddleware from @nevermined-io/payments/express handles the entire x402 flow:
- Returns
402withpayment-requiredheader when no token is provided - Verifies the x402 token via the Nevermined facilitator
- Burns credits after request completion
- Returns
payment-responseheader with settlement receipt
x402 Headers
The middleware follows the x402 HTTP transport spec:Route Configuration
Fixed Credits
Dynamic Credits
Calculate credits based on request/response:Path Parameters
With Agent ID
Payment Scheme (Crypto vs. Fiat)
The middleware auto-detects the payment scheme from plan metadata. Plans with fiat pricing (isCrypto: false) automatically use nvm:card-delegation (Stripe), while crypto plans use nvm:erc4337.
You can explicitly override the scheme in the route configuration:
The middleware automatically detects the payment scheme from plan metadata.
Plans with fiat pricing (
isCrypto: false) use nvm:card-delegation (Stripe).
No code changes are needed on the agent side. You can explicitly override with
the scheme parameter.Middleware Options
Complete Example
See the complete working example in the http-simple-agent tutorial on GitHub.Client Implementation
For fiat plans, clients can use
resolveScheme() to auto-detect the payment scheme before generating tokens. See the x402 developer guide for details on scheme resolution and X402TokenOptions.Environment Variables
Next Steps
Payment Patterns
Advanced credit charging patterns
x402 Protocol
Deep dive into x402 payment flows
Payment Models
Configure credits, subscriptions, and dynamic pricing
http-simple-agent Tutorial
Complete working example on GitHub