OMPX JavaScript SDK
    Preparing search index...

    Class OmpxServer

    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: '...' })
    }
    Index

    Constructors

    Methods

    • Build receipt headers to attach to the 200 response after successful payment.

      Parameters

      Returns Headers

    • Returns a handler function that enforces payment for the protected resource.

      The returned function:

      1. Checks if the request has a payment credential
      2. If not → returns a 402 response with challenges for all configured methods
      3. If yes → verifies the payment, settles it, returns paid context

      Parameters

      Returns (request: Request) => Promise<ChargeResult>