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
| Package | Description |
|---|---|
@paygate/core | Chain-agnostic base client - handles the x402 HTTP flow |
@paygate/client-ethereum | EVM client (Base, Polygon, etc.) - EIP-3009 + viem |
@paygate/client-cosmos | Cosmos SDK client - CosmJS + Keplr / Leap |
@paygate/client-solana | Solana 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 responseThe 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
- Core - base class, types, utilities
- Ethereum / EVM - MetaMask, private key, viem
- Cosmos - Keplr, Leap, CosmJS mnemonic
- Solana - Phantom, wallet adapter