Skip to content

NPM Modules

The @paygate TypeScript monorepo provides client libraries for interacting with x402-protected resources from any JavaScript/TypeScript application - browser, Node.js, or edge runtime.

Packages

PackageDescription
@paygate/coreChain-agnostic base client - handles the x402 HTTP flow
@paygate/client-ethereumEVM client (Base, Polygon, etc.) - EIP-3009 + viem
@paygate/client-cosmosCosmos SDK client - CosmJS + Keplr / Leap
@paygate/client-solanaSolana client - @solana/kit + Phantom

How It Works

Each chain-specific package extends BaseX402Client from @paygate/core. You call fetchWithPayment(url) and the library handles the entire x402 flow transparently:

Your Code ──► fetchWithPayment(url)


              Initial HTTP request

              ┌─────▼──────┐
              │ 200 OK?    │──► return response
              └─────┬──────┘
                    │ 402

          Parse PaymentRequirements


        Sign payment (chain-specific)


          Retry with X-PAYMENT header


              return response

The same flow works for both REST APIs (HTTP 402) and JSON-RPC endpoints (error code 402).

Quick Example

typescript
import { EthereumX402Client, InjectedWalletConnector } from '@paygate/client-ethereum'

const client = new EthereumX402Client({
  walletConnector: new InjectedWalletConnector(), // MetaMask
  chainId: 84532, // Base Sepolia
})

// Automatically handles 402 → sign → retry
const response = await client.fetchWithPayment('https://api.example.com/premium')
const data = await response.json()

Package Docs

Released under the MIT License.