Prerequisites
Before you begin, ensure you have:- A crypto wallet with USDC (any EVM or SVM compatible wallet)
- Node.js and npm, Go, or Python and pip
- A service that requires payment via x402
There are pre-configured examples available in the x402 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:Aptos
Use the Aptos TypeScript SDK to instantiate a signer:Algorand (AVM)
Use the@x402/avm package to instantiate a signer:
Stellar
Use the Stellar SDK 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
Payment Schemes
The examples above use the simplest fixed-price scheme. If a resource advertises a different scheme in its 402 response, register that scheme for the same network namespace:exact: fixed-price payments.upto: usage-based payments where you authorize a maximum and the seller charges actual usage.batch-settlement: high-volume payments where the client deposits into escrow, signs off-chain vouchers, and the seller claims value onchain in batches.
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,@x402/aptos) - Create a wallet signer
- Create an
x402Clientand register payment schemes (exactfor fixed-price,uptofor usage-based billing,batch-settlementfor batched EVM micropayments when the server advertises it) - 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 — including
uptowhere you only pay the actual usage
Next Steps:
- Explore Advanced Concepts like lifecycle hooks for custom logic before/after verification/settlement
- Explore Extensions like Bazaar for service discovery