Pay any HTTP 402 merchant on any chain. Auto-detects x402 or MPP, bridges funds via Across.
npm install universal-payimport { createUniversalFetchWithAcross } from 'universal-pay'
const client = createUniversalFetchWithAcross({
privateKey: process.env.UNIVERSAL_PAY_KEY as `0x${string}`,
})
// Pays automatically — detects protocol, bridges if needed
const response = await client.fetch('https://merchant.example.com')- Probe — makes the request, gets
402 Payment Required - Detect — reads headers:
PAYMENT-REQUIRED= x402,WWW-Authenticate= MPP - Bridge — if funds are on the wrong chain, bridges via Across
- Pay — replays the request through the native protocol adapter
createUniversalFetchWithAcross({
privateKey: process.env.UNIVERSAL_PAY_KEY as `0x${string}`, // required
polyfill: false, // replace globalThis.fetch (default: false)
across: {
originChainIds: [42161, 8453], // chains to scan for funds
rpcs: { 42161: 'https://...' }, // custom RPCs
},
})MIT