SDK
The official x402 SDK for multi-chain payments.
📦 SDK Updated to v1.3
The x402 SDK has been updated to v1.3 (released January 17, 2026). This release includes new features, bug fixes, and performance improvements. See the full changelog for details.
Run npm install @dexterai/x402@latest to update.
@dexterai/x402
The official SDK for x402 payments (currently v1.3). Works with Solana, Base, Polygon, Avalanche, and all supported chains. Full Phantom wallet support.
Package Exports
Client SDK
The client SDK handles the entire x402 flow automatically. When a server returns 402 Payment Required, the client:
- Parses payment requirements from the
PAYMENT-REQUIREDheader - Prompts the user to sign a transaction
- Retries the request with the
PAYMENT-SIGNATUREheader - Returns the response
Basic Usage
Configuration Options
| Option | Type | Required | Description |
|---|---|---|---|
wallets | { solana?, evm? } | Yes | Multi-chain wallets |
wallet | SolanaWallet | No | Single Solana wallet (legacy) |
preferredNetwork | string | No | Prefer this network when multiple options available |
rpcUrls | Record<string, string> | No | RPC endpoints per network (defaults to Dexter proxy) |
maxAmountAtomic | string | No | Maximum payment cap |
verbose | boolean | No | Enable debug logging |
Custom RPC URLs
RPC URLs are optional—the SDK uses Dexter's RPC proxy by default. Override if needed:
React Hook
The useX402Payment hook provides a complete payment flow for React apps. Works with @solana/wallet-adapter-react and wagmi out of the box.
Basic Usage
Return Values
| Property | Type | Description |
|---|---|---|
fetch | function | Payment-aware fetch |
isLoading | boolean | Payment in progress |
status | string | 'idle' | 'pending' | 'success' | 'error' |
error | X402Error? | Error details if failed |
transactionId | string? | Transaction signature |
transactionUrl | string? | Block explorer link |
balances | Balance[] | Token balances per chain |
connectedChains | { solana, evm } | Which chains are connected |
refreshBalances | function | Manual balance refresh |
reset | function | Clear state |
Multi-Chain Display
Server SDK
The server SDK helps you accept x402 payments. It handles payment requirement generation and settlement.
Basic Usage
Base (EVM) Server
Configuration Options
| Option | Type | Required | Description |
|---|---|---|---|
payTo | string | Yes | Your wallet address to receive payments |
network | string | Yes | Network identifier (see Supported Networks) |
facilitatorUrl | string | No | Facilitator URL (defaults to x402.dexter.cash) |
asset | { address, decimals } | No | Token config (defaults to USDC) |
Dynamic Pricing
Charge based on input size - characters, bytes, records, or any unit. No external dependencies.
Token Pricing (LLM)
Accurate token-based pricing for LLMs using tiktoken. Supports OpenAI models out of the box, plus custom rates for Anthropic, Gemini, Mistral, or any model.
OpenAI Models
Custom Models (Anthropic, Gemini, etc.)
Available Models
Tiers: fast, standard, reasoning, premium, custom
Utilities
Supported Networks
| Network | Identifier | Asset |
|---|---|---|
| Solana Mainnet | solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp | USDC |
| Solana Devnet | solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1 | USDC |
| Base Mainnet | eip155:8453 | USDC |
| Base Sepolia | eip155:84532 | USDC |
The SDK also supports v1 legacy identifiers for backward compatibility: solana, solana-devnet, base, base-sepolia.
Version Compatibility
The SDK automatically handles x402 version compatibility:
- v2: Uses CAIP-2 network identifiers (
solana:5eykt...,eip155:8453) - v1: Uses legacy identifiers (
solana,base)
When a server returns a 402 response, the SDK echoes back the same x402Version that was requested. This ensures compatibility with both v1-only and v2-only facilitators.
Error Handling
Error Codes
| Code | Description |
|---|---|
INSUFFICIENT_BALANCE | Not enough USDC to complete payment |
USER_REJECTED | User rejected the transaction |
SETTLEMENT_FAILED | Facilitator failed to settle |
NETWORK_ERROR | Network connectivity issue |
INVALID_RESPONSE | Server returned invalid payment requirements |
TypeScript
The SDK is fully typed. Key types:
Support
- Live Demo: dexter.cash/sdk
- Debug Console: dexter.cash/sdk/debug
- Telegram: @dexteraisol
- Twitter: @dexteraisol
- GitHub Issues: dexter-x402-sdk/issues

SDK