Overview
This guide shows you how to implement x402 payments using Dynamic’s wallet infrastructure. We use thex402-fetch library in the example; you can also use x402-axios or other HTTP clients that support x402.
Dynamic supports multiple wallet options with x402, from embedded MPC wallets to external wallet integrations.
This recipe uses the Dynamic JavaScript SDK (
@dynamic-labs-sdk/client + @dynamic-labs-sdk/evm + @dynamic-labs-sdk/react-hooks). See the React Quickstart for the base setup.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
- Onchain settlement
- Compliance and risk screening
- Integration with official client libraries (
x402-fetch,x402-axios—see Installation)
Prerequisites
Before implementing x402 with Dynamic, ensure you have:- A Dynamic project set up with your environment ID and the JS SDK wired up
- Basic understanding of HTTP status codes and request/response patterns
- x402 fetch library installed (or axios/other HTTP library)
Installation
Install the x402 libraries. These libraries add simple request middleware to wrap your HTTP calls with x402 payment handling.The x402 libraries are the official packages from Coinbase Developer Platform. You can also use other HTTP libraries with x402, but the official packages provide the best integration experience.
Implementation
x402-fetch expects a viemWalletClient. The JS SDK gives you one via createWalletClientForWalletAccount. Read the active EVM wallet account from useWalletAccounts, narrow it with isEvmWalletAccount, and pass the resulting client to wrapFetchWithPayment.
<DynamicProvider> tree. The wallet.address returned by useWalletAccounts is reactive — log out / switch wallets and the component re-renders automatically.