@routexcc/x402
v1.0.3
Published
x402 middleware wrapper for Routex
Maintainers
Readme
@routexcc/x402
x402 payment protocol middleware for Routex — the multi-chain settlement cost router.
Install
npm install @routexcc/core @routexcc/x402Usage
Intercept 402 Payment Required responses and route payments automatically:
import { routexMiddleware } from '@routexcc/x402';
const middleware = routexMiddleware({
routeConfig: {
adapters,
feeOracle,
strategy: 'cheapest',
maxFeeAgeMs: 60_000,
},
signer: mySigner,
onRouteSelected: (result) => console.log(`Paying via ${result.chainId}`),
onRouteFailed: (error) => console.error('Routing failed:', error),
});
// When you get a 402 response:
const parsed = middleware.parseResponse(402, responseBody);
if (parsed) {
const { payload, chainId } = await middleware.handlePaymentRequired(parsed);
// payload is ready to submit to the facilitator
}Exports
routexMiddleware(config)— create a middleware instanceRoutexMiddleware— middleware interface withhandlePaymentRequired()andparseResponse()RoutexMiddlewareConfig,ParsedX402Response,MiddlewareResult— types
Documentation
See the full documentation for routing strategies, configuration, and security model.
License
MIT
