Dexter
Dexter
Docs

@dexterai/x402

@dexterai/x402 is Dexter's full-stack x402 SDK.

It is the package you use when you want to:

  • protect an API endpoint with x402 payments
  • make x402 payments from Node.js scripts
  • make x402 payments from browser apps
  • add payment-aware React UI flows
  • use Access Pass instead of signing every request
  • implement dynamic or token-based pricing

When To Use It

Use @dexterai/x402 when you are building:

  • a paid API
  • a wallet-connected browser app
  • a React application that needs payment state
  • a client that should handle 402 Payment Required automatically
  • an endpoint that needs dynamic or usage-based pricing

Do not use this package when your main goal is:

  • OpenClaw-native agent payments: use @dexterai/clawdexter
  • local stdio discovery/payment for editor or CLI agents: use @dexterai/opendexter

Install

npm install @dexterai/x402

What It Exports

The published package currently exports:

  • @dexterai/x402/client
  • @dexterai/x402/server
  • @dexterai/x402/react
  • @dexterai/x402/adapters
  • @dexterai/x402/utils

Which Surface To Use

client

Use @dexterai/x402/client when you need payment-aware fetch behavior.

The main entry points documented in the source README are:

  • wrapFetch
  • createX402Client
  • createKeypairWallet

Use wrapFetch for Node.js scripts and server-side callers.

Use createX402Client for browser or wallet-connected environments.

server

Use @dexterai/x402/server when you are protecting endpoints or building seller infrastructure.

Main server surfaces documented in the package source:

  • x402Middleware
  • x402AccessPass
  • createX402Server
  • createDynamicPricing
  • createTokenPricing

react

Use @dexterai/x402/react when you want hook-based payment state in a React app.

Main React surfaces:

  • useX402Payment
  • useAccessPass

adapters

Use @dexterai/x402/adapters when you need lower-level chain adapter control.

Examples listed in the source README:

  • createSolanaAdapter
  • createEvmAdapter

utils

Use @dexterai/x402/utils for amount conversion helpers.

Examples listed in the source README:

  • toAtomicUnits
  • fromAtomicUnits

Minimal Paths

Fastest buyer path: Node.js client

import { wrapFetch } from '@dexterai/x402/client';
 
const x402Fetch = wrapFetch(fetch, {
  walletPrivateKey: process.env.SOLANA_PRIVATE_KEY,
});
 
const response = await x402Fetch('https://api.example.com/protected');

Fastest browser path

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

Fastest seller path

import express from 'express';
import { x402Middleware } from '@dexterai/x402/server';
 
const app = express();
 
app.get(
  '/api/protected',
  x402Middleware({
    payTo: 'YourSolanaAddress...',
    amount: '0.01',
  }),
  (req, res) => {
    res.json({ data: 'protected content' });
  },
);

Supported Networks

The package source README explicitly documents verified support for:

  • Solana Mainnet
  • Base Mainnet

The package metadata and docs in this repo also position the SDK around:

  • Polygon
  • Arbitrum
  • Optimism
  • Avalanche

For exact current chain support and facilitator behavior, use:

What The SDK Covers

The source README and this docs section together confirm coverage for:

  • automatic 402 handling
  • client fetch wrappers
  • browser wallet flows
  • React hooks
  • Express middleware
  • Access Pass
  • dynamic pricing
  • token pricing
  • facilitator-based settlement

Common Failure Modes

Wrong wallet context

The client needs a compatible wallet for a chain the endpoint accepts.

Missing funds

The payment flow cannot complete if the configured wallet is not funded with USDC on the accepted chain.

Choosing the wrong surface

Use:

  • wrapFetch for Node scripts
  • createX402Client for browser apps
  • useX402Payment for React UI
  • x402Middleware for protected endpoints
  • x402AccessPass when repeated reads should not require repeated signing

Needing package-level detail but starting in the wrong page

If you are here for one specific implementation path, jump directly to the specialized subpages below.