@dexterai/x402 SDK
Chain-agnostic x402 payments for Solana & Base. This demo uses the useX402Payment React hook.
Pay with Solana
Make a real x402 payment on Solana mainnet using the useX402Payment hook. The hook handles the full 402 flow automatically.
Pay with Base
Make a real x402 payment on Base mainnet using the useX402Payment hook. Same hook, different chain—it handles it seamlessly.
Real AI Chat
Live DemoThis is real. Type a prompt, pay with Solana, and get a response from gpt-4o-mini. Price scales dynamically with prompt length. Chain-agnostic x402!
Code Examples
import { createX402Client } from '@dexterai/x402/client'; import { createSolanaAdapter, createEvmAdapter } from '@dexterai/x402/adapters'; const client = createX402Client({...}); // Auto-handles 402 → sign → retry const res = await client.fetch('/api/paid-endpoint');
import { createX402Server } from '@dexterai/x402/server'; const server = createX402Server({...}); // Generate 402 response const requirements = await server.buildRequirements({ amountAtomic: '30000', // $0.03 resourceUrl: '/api/endpoint', });
One hook, full state
Get fetch, loading, balances, transaction URLs, and error handling in one hook.
Generate compliant headers
Create requirements and encode the response without hand-rolling header formats.
Wallet signing built-in
Plug in Solana or EIP-712 wallets with the official adapters—no custom signing layer.
Pay per token
Accurate pricing using tiktoken. Real OpenAI rates per 1M tokens with quote hash validation.
import { createTokenPricing } from '@dexterai/x402/server'; const pricing = createTokenPricing({ model: 'gpt-4o-mini' }); const quote = pricing.calculate(prompt); // quote.inputTokens, quote.usdAmount, quote.quoteHash // Uses tiktoken + real OpenAI rates automatically