OMPX JavaScript SDK
    Preparing search index...

    Class OmpxClient

    OMPX client — automatically handles payments for both X402 and MPP services.

    import { OmpxClient } from '@ompx/client'
    import { tempo } from '@ompx/tempo'
    import { privateKeyToAccount } from 'viem/accounts'

    const client = new OmpxClient({
    methods: [tempo({ account: privateKeyToAccount('0x...') })],
    })

    client.polyfill() // Patches globalThis.fetch
    const response = await fetch('https://api.example.com/resource')
    const { fetch: ompxFetch } = client.wrapFetch(globalThis.fetch)
    const response = await ompxFetch('https://api.example.com/resource')
    const receipt = client.parseReceipt(response)
    Index

    Constructors

    Methods

    • Manually create a payment credential for a 402 response. Returns the headers to include in the retry request.

      Parameters

      • response: Response

      Returns Promise<{ headers: Record<string, string> }>

    • Polyfill globalThis.fetch to automatically handle 402 Payment Required responses. After calling this, all fetch() calls will transparently pay for resources.

      Returns void

    • Wrap a fetch function to automatically handle 402 Payment Required responses. Returns a new fetch function that transparently pays for resources.

      Parameters

      • fetchFn: {
            (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
            (input: string | URL | Request, init?: RequestInit): Promise<Response>;
        }
          • (input: URL | RequestInfo, init?: RequestInit): Promise<Response>
          • Parameters

            • input: URL | RequestInfo
            • Optionalinit: RequestInit

            Returns Promise<Response>

          • (input: string | URL | Request, init?: RequestInit): Promise<Response>
          • Parameters

            • input: string | URL | Request
            • Optionalinit: RequestInit

            Returns Promise<Response>

      Returns {
          fetch: {
              (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
              (input: string | URL | Request, init?: RequestInit): Promise<Response>;
          };
      }

      • fetch: {
            (input: URL | RequestInfo, init?: RequestInit): Promise<Response>;
            (input: string | URL | Request, init?: RequestInit): Promise<Response>;
        }