Dexter
Dexter
Docs

Browser Client

Client integration
Automatic 402 handling in wallet-connected UIs

Use the browser client when you want fetch-like ergonomics with real x402 payment behavior, multi-wallet awareness, and explicit network control.

Use the browser client when your application already has wallet connectivity and you want fetch() to become payment-aware.

Best Fit

This path is ideal for:

  • consumer web apps
  • dashboards and internal tools
  • agent-adjacent browser UIs
  • flows where a human wallet confirms payment in the browser

Minimal Example

import { createX402Client } from '@dexterai/x402/client';
 
const client = createX402Client({
  wallets: {
    solana: solanaWallet,
    evm: evmWallet,
  },
});
 
const response = await client.fetch('https://api.example.com/protected');
const data = await response.json();

What This Does

When the endpoint returns 402 Payment Required, the client:

  1. parses the payment requirements
  2. picks a compatible wallet/network
  3. signs the payment
  4. retries the request automatically

Adding Custom RPC URLs

Use custom RPC URLs when you need explicit provider control instead of the Dexter defaults.

import { createX402Client } from '@dexterai/x402/client';
 
const client = createX402Client({
  wallets: {
    solana: solanaWallet,
    evm: evmWallet,
  },
  rpcUrls: {
    'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': 'https://your-solana-rpc.example',
    'eip155:8453': 'https://mainnet.base.org',
  },
});

Keep the x402 client near your API layer rather than scattering payment behavior across components.

import { createX402Client } from '@dexterai/x402/client';
 
export function createPaidApiClient({
  solanaWallet,
  evmWallet,
}: {
  solanaWallet?: unknown;
  evmWallet?: unknown;
}) {
  return createX402Client({
    wallets: {
      solana: solanaWallet,
      evm: evmWallet,
    },
    preferredNetwork: 'eip155:8453',
    maxAmountAtomic: '250000',
  });
}

That gives you one place to control:

  • wallet selection
  • preferred network
  • payment caps
  • RPC policy

When To Use Something Else

On this page