Set Up a Wallet
Give your AI agent a wallet for autonomous x402 payments.
Why a Wallet?
x402 payments require signing. Your agent needs a wallet with:
- USDC on Base — the payment token
- A private key — to sign payment proofs
Option 1: Coinbase AgentKit (Recommended)
Coinbase built AgentKit specifically for AI agents.
npm install @coinbase/agentkit
import { CdpClient } from "@coinbase/cdp-sdk"; const cdp = new CdpClient(); const wallet = await cdp.evm.createWallet(); console.log("Address:", wallet.address); // Fund this address with USDC on Base
Why AgentKit:
- No private key management
- Built-in spending limits
- Gasless transactions
- x402 native support
Option 2: Raw Private Key
For custom integrations or full control.
Generate a Wallet
# Using cast (Foundry) cast wallet new # Or Node.js node -e " const { Wallet } = require('ethers'); const w = Wallet.createRandom(); console.log('Address:', w.address); console.log('Private Key:', w.privateKey); "
Store Securely
Never commit private keys to git. Use:
- Environment variables
- 1Password / secrets manager
- Hardware wallet (advanced)
export AGENT_PRIVATE_KEY="0x..."
Use in Your Agent
import { Wallet } from "ethers"; const wallet = new Wallet(process.env.AGENT_PRIVATE_KEY); // Sign x402 payments with this wallet
Fund Your Wallet
Send USDC on Base to your agent's address.
From Coinbase
- Open Coinbase app
- Select USDC → Send
- Enter your agent's address
- Select Base network (not Ethereum!)
- Send $5-10 to start
From Any Exchange
Most exchanges support Base withdrawals. Select "Base" or "Base Mainnet" when withdrawing USDC.
For Testing
Use Base Sepolia (testnet) with fake USDC:
- Get test ETH from Alchemy faucet
- Test USDC contract:
0x036CbD53842c5426634e7929541eC2318f3dCF7e
Check Your Balance
# Using cast cast call 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 \ "balanceOf(address)" YOUR_ADDRESS \ --rpc-url https://mainnet.base.org
Or check basescan.org with your address.
Security Tips
- Start small — $10-20 is plenty for testing
- Use spending limits — cap per-transaction amounts
- Separate wallets — each agent gets its own wallet
- Monitor spending — check transaction history regularly
Next Steps
- Your first payment — test the full flow
- SDK reference — handles payment signing automatically