JavaScript Library
Complete guide to @transx402/client — installation, configuration, paywall component, and API reference for IDRX payment integration.
Overview
@transx402/client is a browser and Node.js library that handles the full x402 payment flow for IDRX. It wraps the standard x402 client libraries and adds IDRX-specific logic: Permit2 approval detection, one-time approval prompts, and preconfigured token/network defaults.
The key design goal: zero friction for website owners — drop in one script tag or npm package, and IDRX payments work.
Installation
NPM (for bundled apps)
CDN (for WordPress, static sites, any HTML page)
For zero-build integrations, see the dedicated CDN Usage guide. The short version:
The CDN script exposes a global TransX402 object with the same API described below.
Initialization
TransX402.create(options)
Create a TransX402 client instance:
The environment (sandbox/production) is determined automatically from the API key prefix — you don't need to set the facilitator URL manually.
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | required | API key from the TransX402 dashboard |
token | string | 'IDRX' | Token symbol to use |
network | string | 'base' | Blockchain network |
onPaymentStart | function | — | Callback when payment starts |
onPaymentSuccess | function | — | Callback when payment succeeds |
onPaymentError | function | — | Callback when payment fails |
onWalletConnect | function | — | Callback when wallet connects |
onApprovalRequired | function | — | Callback when Permit2 approval is needed |
Core API
client.fetch(url, options)
Drop-in replacement for fetch(). Automatically handles 402 responses.
Internal flow:
- Sends a normal
fetch()request - If response is 402, parses payment requirements
- Connects wallet (if not connected)
- Checks Permit2 approval (prompts if needed — one time only)
- Signs Permit2 authorization
- Sends signed authorization to facilitator
- Retries original request with payment proof
- Returns the final response
client.connectWallet()
Explicitly connect a wallet. Supports:
- MetaMask / browser extension wallets (EIP-1193)
- WalletConnect v2
- Coinbase Wallet
client.checkApproval()
Check if the connected wallet has approved Permit2 for IDRX.
client.requestApproval()
Request Permit2 approval from the user. Only needed once per wallet.
client.pay(paymentRequirements)
Manually trigger a payment without wrapping fetch.
Paywall Component
A ready-made paywall overlay for content gating.
Vanilla JavaScript
React
Paywall Display
The default paywall overlay includes:
- Price display in IDR (e.g., "Rp 5,000")
- "Pay with IDRX" button
- Wallet connection flow (if not connected)
- Permit2 approval step (if first time, with explanation)
- Payment confirmation with transaction link
- Customizable via CSS variables
Customization
CSS Variables
Event Hooks
Multi-Currency Support
The library is designed for IDRX first but supports additional tokens:
Token configuration (addresses, decimals, methods) is fetched from the facilitator's /tokens endpoint, so adding new tokens requires no client library updates.
Bundle Size Targets
| Variant | Target |
|---|---|
| Core (fetch wrapper only) | < 15 KB gzipped |
| With paywall UI | < 30 KB gzipped |
| With wallet connectors | < 50 KB gzipped |
| CDN full bundle | < 60 KB gzipped |
Compatibility
Browser
- Chrome 90+
- Firefox 90+
- Safari 15+
- Edge 90+
- Mobile: Chrome Android, Safari iOS
Node.js
- Node.js 18+ (Fetch API required)
- Can be used server-side for programmatic payments (AI agents, backends)