CHAPTER 4 of 11

Multi-Chain

One framework, multiple networks: Solana, Base, Polygon, Arbitrum.
A static explanation. This chapter's live demo paid on four production networks through server-side services that the public gateway does not run. Chapters 1 to 3 run live on Solana devnet; this page explains how the multi-chain framework works.

The hurdle

Chapters 1 to 3 were all Solana. Buyers hold USDC on many chains. Accepting payment on each of them should not mean building a second, third and fourth copy of the payment stack.

The move: one client, one adapter per chain family

The client is a small ES module with a chain-adapter registry. The page registers one adapter per network it accepts; the client handles wallet discovery, the payment flow and the receipt the same way for every chain.

const client = createX402Client({ orderId, resourceServerVerifyUrl }) client.registerChain('solana', createSolanaAdapter({ recipient, rpc })) client.registerChain('base', createEvmAdapter({ chainId: 8453, recipient, rpc })) client.registerChain('polygon', createEvmAdapter({ chainId: 137, recipient, rpc })) client.registerChain('arbitrum', createEvmAdapter({ chainId: 42161, recipient, rpc }))
Solana adapterDetects installed Solana wallets (Phantom, Solflare, Backpack and others), builds an SPL USDC transfer, signed in the wallet.
EVM adapterOne file for Base, Polygon and Arbitrum: the chain ID and the USDC contract come from configuration. Adding a network is a config entry.

How a payment is verified

  1. The buyer picks a wallet and a chain; the adapter builds a USDC transfer to the seller's address on that chain.
  2. The wallet signs and sends it. The page gets a transaction hash.
  3. The page asks the server to verify. The server re-reads the transaction from the chain itself: the status, the token contract, the recipient, and the net USDC that arrived (every transfer to and from the recipient in that transaction, added up), so a payment that is refunded in the same transaction does not count.
  4. The server refuses a transaction hash it has already accepted (replay protection, keyed by chain and hash).
  5. Only then does the content unlock. Nothing the browser says about the payment is trusted.

Wallets the framework detects

Ethereum-compatible wallets are found through automatic wallet discovery and appear beside the Solana ones.