Framework-agnostic OMPX server. Handles the full X402 + MPP payment verification flow.
Use the framework-specific packages (@ompx/hono, @ompx/express, etc.) for HTTP framework integration.
import { OmpxServer } from '@ompx/server'import { tempo } from '@ompx/tempo'const server = new OmpxServer({ methods: [tempo({ recipient: '0x...', currency: '0x20c0...' })],})// Use in any Fetch API-compatible handler:async function handler(request: Request): Promise<Response> { const result = await server.charge({ amount: '0.01' })(request) if (result.status === '402') return new Response(null, { status: 402, headers: result.headers }) if (result.status === 'forbidden') return new Response(null, { status: 403 }) return Response.json({ data: '...' })} Copy
import { OmpxServer } from '@ompx/server'import { tempo } from '@ompx/tempo'const server = new OmpxServer({ methods: [tempo({ recipient: '0x...', currency: '0x20c0...' })],})// Use in any Fetch API-compatible handler:async function handler(request: Request): Promise<Response> { const result = await server.charge({ amount: '0.01' })(request) if (result.status === '402') return new Response(null, { status: 402, headers: result.headers }) if (result.status === 'forbidden') return new Response(null, { status: 403 }) return Response.json({ data: '...' })}
Build receipt headers to attach to the 200 response after successful payment.
Optional
Returns a handler function that enforces payment for the protected resource.
The returned function:
Framework-agnostic OMPX server. Handles the full X402 + MPP payment verification flow.
Use the framework-specific packages (@ompx/hono, @ompx/express, etc.) for HTTP framework integration.
Example