Overview
This guide shows you how to implement x402 payments using Dynamic’s wallet infrastructure on EVM and Solana. On EVM we use@x402/fetch (or @x402/axios) with @x402/evm. On Solana we use x402-solana, which accepts any wallet with address and signTransaction.
Dynamic supports embedded wallets and external wallets for both chains.
This recipe uses the Dynamic JavaScript SDK (
@dynamic-labs-sdk/client + @dynamic-labs-sdk/react-hooks) with either @dynamic-labs-sdk/evm or @dynamic-labs-sdk/solana. See the React Quickstart for the base setup. For Solana, call addSolanaExtension() when you initialize the client.The x402 protocol
The x402 payment protocol defines how onchain payment is negotiated over HTTP 402 responses: the server returns payment requirements; the client signs and retries the request (often with anX-Payment header); a facilitator can verify and help settle onchain.
The Fireblocks x402 facilitator runs facilitator infrastructure used by many x402 integrations, including:
- Zero-fee USDC payments on Base (and other supported networks, including Solana)
- Onchain settlement
- Compliance and risk screening
- Integration with client libraries (see Installation)
Prerequisites
Before implementing x402 with Dynamic, ensure you have:- A Dynamic project with your environment ID and the JS SDK wired up
- EVM and/or Solana enabled in the dashboard, matching the chain you will pay on
- Basic understanding of HTTP status codes and request/response patterns
- The x402 client package for your chain (see Installation)
Installation
Install the x402 client for your chain. These libraries wrap your HTTP calls with payment handling when the server returns 402. On EVM you also need@x402/evm, which provides the ExactEvmScheme used to sign payments.
- EVM
- Solana
@x402/fetch and @x402/axios are the official x402 protocol v2 packages (the older x402-fetch / x402-axios packages are v1 and deprecated). You can use other HTTP libraries with x402, but these provide the best EVM integration experience.Implementation
Connect a wallet account for your chain, adapt it to the x402 client’s expected signer, then call the protected URL. The client handles the 402 challenge, signing, and retry.- EVM
- Solana
Create a viem
WalletClient with createWalletClientForWalletAccount, register its account with x402’s ExactEvmScheme, then wrap fetch with wrapFetchWithPaymentFromConfig so x402 handles the 402 challenge and payment automatically. Read the active EVM wallet account from useGetWalletAccounts and narrow it with isEvmWalletAccount.<DynamicProvider> tree. The wallet accounts from useGetWalletAccounts are reactive: log out or switch wallets and the component re-renders automatically.