Live on Mainnet · Using React Hook

@dexterai/x402 SDK

Chain-agnostic x402 payments for Solana & Base. This demo uses the useX402Payment React hook.

SolanaSolanaBaseBasex402 v2React Hook
Solana

Pay with Solana

USDC$0.03

Make a real x402 payment on Solana mainnet using the useX402Payment hook. The hook handles the full 402 flow automatically.

Base

Pay with Base

USDC$0.03

Make a real x402 payment on Base mainnet using the useX402Payment hook. Same hook, different chain—it handles it seamlessly.

🤖

Real AI Chat

Live Demo
USDC$0.00

This 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!

Input Tokens
48
Tier
fast
Cost
USDC$0.00
Token-Based Pricing: Your prompt is tokenized server-side using tiktoken. Price = (input tokens × rate/1M). Quote hash prevents manipulation.
💻

Code Examples

Request402 ChallengeSignRetry OK
Step 1 · Client RequestBrowser or Node · auto-retry on 402
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');
Step 2 · Server RequirementsExpress or Next.js · headers + policy
import { createX402Server } from '@dexterai/x402/server';

const server = createX402Server({...});

// Generate 402 response
const requirements = await server.buildRequirements({
  amountAtomic: '30000',  // $0.03
  resourceUrl: '/api/endpoint',
});
ReactuseX402Payment

One hook, full state

Get fetch, loading, balances, transaction URLs, and error handling in one hook.

ServerbuildRequirements

Generate compliant headers

Create requirements and encode the response without hand-rolling header formats.

AdaptersSolana + EVM

Wallet signing built-in

Plug in Solana or EIP-712 wallets with the official adapters—no custom signing layer.

PricingToken-Based

Pay per token

Accurate pricing using tiktoken. Real OpenAI rates per 1M tokens with quote hash validation.

🎯Accurate PricingToken-Based LLM Pricing
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