Migration Guide: V1 to V2
This guide helps you migrate from x402 V1 to V2. The V2 protocol introduces standardized identifiers, improved type safety, and a more modular architecture.
Overview
Payment Header
X-PAYMENT
PAYMENT-SIGNATURE
Response Header
X-PAYMENT-RESPONSE
PAYMENT-RESPONSE
Network Format
String (base-sepolia)
CAIP-2 (eip155:84532)
Version Field
x402Version: 1
x402Version: 2
Packages
x402, x402-express, x402-axios
@x402/core, @x402/express, @x402/axios, @x402/evm
For Buyers (Client-Side)
Before (V1)
import { withPaymentInterceptor } from "x402-axios";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { baseSepolia } from "viem/chains";
import axios from "axios";
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const walletClient = createWalletClient({
account,
chain: baseSepolia,
transport: http(),
});
// V1 pattern
const api = withPaymentInterceptor(
axios.create({ baseURL: "https://api.example.com" }),
walletClient,
);
const response = await api.get("/paid-endpoint");After (V2)
Key Changes
Package rename:
x402-axios→@x402/axiosFunction rename:
withPaymentInterceptor→wrapAxiosWithPaymentWallet setup: Use
x402ClientwithregisterExactEvmSchemehelper instead of passing wallet directlyNo chain-specific configuration: The V2 client automatically handles network selection based on payment requirements
For Sellers (Server-Side)
Before (V1)
After (V2)
Key Changes
Package rename:
x402-express→@x402/expressConfiguration structure: Route config now uses
acceptsarray with explicitscheme,network, andpayToNetwork format:
base-sepolia→eip155:84532(CAIP-2 standard)Resource server: Create
x402ResourceServerwith facilitator client and register schemes using helper functionsPrice recipient: Explicitly specify
payToaddress per route
Network Identifier Mapping
base-sepolia
eip155:84532
84532
Base Sepolia Testnet
base
eip155:8453
8453
Base Mainnet
ethereum
eip155:1
1
Ethereum Mainnet
sepolia
eip155:11155111
11155111
Ethereum Sepolia Testnet
solana-devnet
solana:devnet
-
Solana Devnet
solana
solana:mainnet
-
Solana Mainnet
Package Migration Reference
x402
@x402/core
x402-express
@x402/express
x402-axios
@x402/axios
x402-fetch
@x402/fetch
x402-hono
@x402/hono
x402-next
@x402/next
(built-in)
@x402/evm (EVM support)
(built-in)
@x402/svm (Solana support)
Header Changes
If you're implementing custom HTTP handling, update your header names:
Troubleshooting
"Cannot find module" errors
Ensure you've installed all V2 packages:
Payment verification failures
Check you're using CAIP-2 network identifiers (
eip155:84532notbase-sepolia)Verify your
payToaddress is correctly configuredEnsure the facilitator URL is correct for your network (testnet vs mainnet)
Mixed V1/V2 compatibility
The facilitator supports both V1 and V2 protocols. During migration, your V2 server can still accept payments from V1 clients, but we recommend updating clients to V2 for full feature support.
Next Steps
Last updated