Setting Up a USDC Wallet for Your OpenClaw Agent
Give your OpenClaw agent its own wallet for autonomous x402 payments. Create a wallet, fund it with USDC on Base, and configure the skill.
OpenClaw is an agent runtime that can connect to messaging platforms, run automations, and call APIs on your behalf. This guide shows you how to give your OpenClaw agent a USDC wallet so it can pay for x402 APIs autonomously.
By the end, your agent will be able to call AgentUtil (or any x402 API) without you manually approving each payment.
What You'll Need
- OpenClaw installed and running
- A wallet with USDC on Base
- 10 minutes
How It Works
The payment flow:
- Your Agent calls an x402 API (like AgentUtil)
- The API returns 402 with payment details
- Your Agent signs a USDC transfer with its wallet
- Your Agent retries with the signed payment
- The Facilitator settles the payment onchain
Your agent holds a wallet. When it hits an x402 API, the API returns 402 with payment details. The agent signs a USDC transfer and retries. The facilitator settles the payment onchain.
Step 1: Create an Agent Wallet
Your agent needs its own wallet — don't use your personal wallet.
Option A: Generate a New Wallet
# Create a new wallet
node -e "
const { Wallet } = require('ethers');
const w = Wallet.createRandom();
console.log('Address:', w.address);
console.log('Private Key:', w.privateKey);
"Save the private key securely. You'll add it to OpenClaw's configuration.
Option B: Use Coinbase Agentic Wallet
If you prefer managed key storage:
npm install -g @coinbase/agentic-wallet
npx awal auth
npx awal addressThis creates a wallet managed by Coinbase — no private key to handle yourself.
Step 2: Fund the Wallet
Send USDC on Base to your agent's wallet address.
From Coinbase
- Open Coinbase
- Select USDC
- Send to your agent's address
- Select Base network (not Ethereum!)
Start small — $5-10 is plenty for testing.
From Another Wallet
If you have USDC on Base already:
# Using cast (Foundry)
cast send 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 \
"transfer(address,uint256)" \
YOUR_AGENT_ADDRESS \
5000000 \ # $5 USDC (6 decimals)
--rpc-url https://mainnet.base.org \
--private-key YOUR_PRIVATE_KEYStep 3: Create an x402 Skill for OpenClaw
OpenClaw uses skills to extend agent capabilities. Create a skill that handles x402 payments:
mkdir -p ~/.openclaw/workspace/skills/x402-wallet
cd ~/.openclaw/workspace/skills/x402-walletCreate the skill file:
cat > SKILL.md << 'EOF'
# x402 Wallet Skill
This skill enables the agent to make x402 payments using USDC on Base.
## Configuration
Set these environment variables:
- `X402_PRIVATE_KEY`: Agent wallet private key
- `X402_NETWORK`: "base" (mainnet) or "base-sepolia" (testnet)
## Usage
When calling an x402 API:
1. Make the initial request
2. If you get a 402 response, parse the `PAYMENT-REQUIRED` header
3. Use the x402-pay tool to sign and submit payment
4. Retry the request with the payment proof
## Tools
### x402-pay
Sign and submit an x402 payment.
```bash
x402-pay --url <api-url> --payment <base64-payment-header>Example
# Call an x402 API
curl -X POST https://api.agentutil.dev/v1/tools/email.verify/tasks \
-H "Content-Type: application/json" \
-d '{"email": "test@example.com"}'
# If 402, extract payment header and pay
x402-pay --url "https://api.agentutil.dev/v1/tools/email.verify/tasks" \
--payment "eyJ4NDAyVmVyc2lvbiI6MSwi..."EOF
Create the payment script:
```bash
cat > x402-pay.ts << 'EOF'
#!/usr/bin/env npx ts-node
import { Wallet } from 'ethers';
const PRIVATE_KEY = process.env.X402_PRIVATE_KEY;
if (!PRIVATE_KEY) {
console.error('X402_PRIVATE_KEY not set');
process.exit(1);
}
const wallet = new Wallet(PRIVATE_KEY);
async function pay(url: string, paymentHeader: string) {
// Decode payment requirements
const requirements = JSON.parse(Buffer.from(paymentHeader, 'base64').toString());
const accept = requirements.accepts[0];
// Create payment message
const message = JSON.stringify({
resource: accept.resource,
amount: accept.maxAmountRequired,
payTo: accept.payTo,
nonce: Date.now().toString(),
});
// Sign it
const signature = await wallet.signMessage(message);
// Create payment proof
const proof = Buffer.from(JSON.stringify({
...JSON.parse(message),
signature,
signer: wallet.address,
})).toString('base64');
// Make paid request
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-payment': proof,
},
});
console.log('Status:', response.status);
console.log('Response:', await response.json());
}
// Parse CLI args
const args = process.argv.slice(2);
const urlIdx = args.indexOf('--url');
const paymentIdx = args.indexOf('--payment');
if (urlIdx === -1 || paymentIdx === -1) {
console.error('Usage: x402-pay --url <url> --payment <base64>');
process.exit(1);
}
pay(args[urlIdx + 1], args[paymentIdx + 1]);
EOF
chmod +x x402-pay.tsStep 4: Configure OpenClaw
Add your wallet to OpenClaw's environment. Edit ~/.openclaw/config.yaml:
# Agent wallet for x402 payments
env:
X402_PRIVATE_KEY: "0x..." # Your agent's private key
X402_NETWORK: "base" # or "base-sepolia" for testnetOr use environment variables:
export X402_PRIVATE_KEY="0x..."
export X402_NETWORK="base"Step 5: Test the Setup
Have your agent call an x402 API:
Hey agent, verify this email using AgentUtil: test@gmail.com
Your agent should:
- Call the API
- Get a 402 response
- Sign the payment with its wallet
- Retry with payment proof
- Return the result
Check the wallet balance to confirm payment went through:
cast call 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 \
"balanceOf(address)" YOUR_AGENT_ADDRESS \
--rpc-url https://mainnet.base.orgSecurity Best Practices
Use Spending Limits
Don't put more than you're willing to lose in the agent wallet. $10-50 is reasonable for most use cases.
Monitor Spending
Check the wallet regularly:
# Add to your HEARTBEAT.md
## Wallet Check
Check agent wallet balance weekly. Alert if below $5.Use Testnet First
Test everything on Base Sepolia before using real money:
export X402_NETWORK="base-sepolia"
export X402_PRIVATE_KEY="0x..." # Testnet walletSeparate Wallets
Each agent should have its own wallet. Don't share private keys across agents.
Using with AgentUtil
Once set up, your agent can call any AgentUtil tool:
# Email verification
POST https://api.agentutil.dev/v1/tools/email.verify/tasks
{"email": "user@example.com"}
# DNS lookup
POST https://api.agentutil.dev/v1/tools/dns.lookup/tasks
{"domain": "example.com"}
# IP geolocation
POST https://api.agentutil.dev/v1/tools/ip.geolocate/tasks
{"ip": "8.8.8.8"}Each call costs $0.002-0.05 in USDC. Your agent handles payment automatically.
Alternative: Use an API Key
If you don't want to manage a wallet, you can prepay via Stripe:
- Sign up at agentutil.dev
- Prepay credits via Stripe
- Use API key instead of x402:
curl -X POST https://api.agentutil.dev/v1/tools/email.verify/tasks \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{"email": "test@example.com"}'This works but requires manual top-ups. x402 is more autonomous.
Troubleshooting
"No X402_PRIVATE_KEY"
Make sure the environment variable is set:
echo $X402_PRIVATE_KEY
# Should print your key (not empty)"Insufficient balance"
Your agent wallet needs USDC on Base. Check balance and fund if needed.
"Invalid signature"
Usually means:
- Wrong network (testnet vs mainnet)
- Wallet not on Base
- Payment expired
"402 but agent didn't pay"
The agent might not have the x402 skill loaded. Check:
ls ~/.openclaw/workspace/skills/x402-wallet/Summary
| Step | Action |
|---|---|
| 1 | Create agent wallet |
| 2 | Fund with USDC on Base |
| 3 | Create x402 skill |
| 4 | Configure OpenClaw with private key |
| 5 | Test with a real API call |
Your OpenClaw agent can now pay for APIs autonomously. No human approval needed, no invoices, no accounts — just USDC and cryptographic signatures.
Resources
Questions? Email silas@agentutil.dev