Prerequisites
Before you begin, ensure you have:- A crypto wallet with USDC (any EVM-compatible wallet)
- Node.js and npm, Go, or Python and pip
- A service that requires payment via x402
We have pre-configured examples available in our repo, including examples for fetch, Axios, Go, and MCP.
1. Install Dependencies
- Node.js
- Go
- Python
Install the x402 client packages:
2. Create a Wallet Signer
- Node.js (viem)
- Go
- Python (eth-account)
Install the required package:Then instantiate the wallet signer:
Solana (SVM)
Use SolanaKit to instantiate a signer:3. Make Paid Requests Automatically
- Fetch
- Axios
- Go
- Python (httpx)
- Python (requests)
@x402/fetch extends the native
fetch API to handle 402 responses and payment headers for you. Full example hereMulti-Network Client Setup
You can register multiple payment schemes to handle different networks:- TypeScript
- Go
- Python
4. Discover Available Services (Optional)
Instead of hardcoding endpoints, you can use the x402 Bazaar to dynamically discover available services. This is especially powerful for building autonomous agents.5. Error Handling
Clients will throw errors if:- No scheme is registered for the required network
- The request configuration is missing
- A payment has already been attempted for the request
- There is an error creating the payment header
Summary
- Install x402 client packages (
@x402/fetchor@x402/axios) and mechanism packages (@x402/evm,@x402/svm) - Create a wallet signer
- Create an
x402Clientand register payment schemes - Use the provided wrapper/interceptor to make paid API requests
- (Optional) Use the x402 Bazaar to discover services dynamically
- Payment flows are handled automatically for you
Next Steps:
- Explore Advanced Concepts like lifecycle hooks for custom logic before/after verification/settlement
- Explore Extensions like Bazaar for service discovery