Baby's First x402 Payment with Base
Your first x402 payment in 10 minutes. Get a wallet, fund it with USDC, and make a real API call. No accounts, no API keys — just crypto.
You've heard about x402. Agents paying for APIs with crypto. Sounds cool, but you've never actually done it. This guide walks you through your first payment — from zero to "holy shit, it worked" in about 10 minutes.
We'll use AgentUtil as our test API and Base as our network. By the end, you'll have made a real x402 payment and gotten real data back.
What You'll Need
- A computer with Node.js installed
- $5 worth of USDC (or less — we're making penny payments)
- 10 minutes
That's it. No accounts to create, no API keys to manage.
Step 1: Get a Wallet
You need a wallet that can hold USDC on Base. The easiest option is Coinbase Wallet.
Option A: Coinbase Wallet (Mobile)
- Download Coinbase Wallet app (not the main Coinbase app)
- Create a new wallet
- Write down your recovery phrase somewhere safe
- Switch to Base network in settings
Option B: MetaMask (Browser)
- Install MetaMask browser extension
- Create a new wallet
- Add Base network:
- Network Name: Base
- RPC URL:
https://mainnet.base.org - Chain ID:
8453 - Currency: ETH
- Explorer:
https://basescan.org
Step 2: Get USDC on Base
You need USDC (a stablecoin worth $1) on the Base network.
From Coinbase
If you have a Coinbase account:
- Buy USDC on Coinbase
- Go to Send
- Enter your wallet address
- Important: Select "Base" as the network
- Send $5-10 worth
Should arrive in a few seconds.
From Another Exchange
Most exchanges now support Base withdrawals. Look for "Base" or "Base Mainnet" when withdrawing USDC.
Bridge from Ethereum
If you have USDC on Ethereum mainnet:
- Go to bridge.base.org
- Connect your wallet
- Select USDC and the amount
- Bridge to Base
Takes a few minutes and costs some ETH gas.
Step 3: Install the x402 Client
Open your terminal:
npm install -g @x402/client
This gives you a command-line tool for making x402 payments.
Step 4: Connect Your Wallet
The x402 client needs access to your wallet to sign payments.
Export Your Private Key
Warning: Your private key controls your money. Never share it. Never paste it in a website. Only use it in tools you trust.
In MetaMask:
- Click the three dots on your account
- Account details → Export private key
- Enter your password
- Copy the key
Set it as an environment variable:
export X402_PRIVATE_KEY="your-private-key-here"
Or create a .env file:
echo "X402_PRIVATE_KEY=your-private-key-here" > ~/.x402env
Step 5: Make Your First Payment
Let's verify an email address. This costs $0.01.
x402 pay https://api.agentutil.dev/v1/tools/email.verify/tasks \
--body '{"email": "test@gmail.com"}'
What happens:
- Client sends POST request
- Server returns 402 with payment details
- Client signs USDC transfer
- Client retries with payment proof
- Server validates and returns result
You should see:
{
"task_id": "task_abc123",
"status": "pending",
"poll_url": "/v1/tasks/task_abc123"
}
Then poll for the result:
curl https://api.agentutil.dev/v1/tasks/task_abc123
{
"status": "complete",
"result": {
"email": "test@gmail.com",
"deliverable": true,
"is_free_email": true,
"is_disposable": false,
"quality_score": 0.95
}
}
Congrats! You just made an x402 payment. Check your wallet — you're $0.01 lighter.
Step 6: Try More APIs
Now that you're set up, try some other tools:
DNS Lookup ($0.002)
x402 pay https://api.agentutil.dev/v1/tools/dns.lookup/tasks \
--body '{"domain": "google.com"}'
IP Geolocation ($0.005)
x402 pay https://api.agentutil.dev/v1/tools/ip.geolocate/tasks \
--body '{"ip": "8.8.8.8"}'
Geocoding ($0.005)
x402 pay https://api.agentutil.dev/v1/tools/geo.locate/tasks \
--body '{"address": "Empire State Building, NYC"}'
Each one: request → 402 → pay → result. Same pattern every time.
What Just Happened?
Let's break down the magic:
The 402 Response
When you first hit the API, it returns:
HTTP/1.1 402 Payment Required
X-Payment: eyJhbW91bnQiOiIwLjAxIiwiY3VycmVuY3kiOiJVU0RDIi4uLn0=
X-Payment-Network: base
X-Payment-Address: 0x124CA4b34041D33914f94Cb5Fbaa5e4075EB08D7
The X-Payment header contains encoded payment details: how much, where to send it, and a nonce to prevent replay attacks.
The Payment
Your client decoded those details and signed a USDC transfer:
- From: Your wallet
- To: AgentUtil's wallet
- Amount: $0.01 USDC
- Network: Base
The signature proves you authorized the payment. The client sent this signature back with the retry request.
The Settlement
AgentUtil's server verified your signature and trusted that the payment would settle. A "facilitator" (usually Coinbase) handles the actual onchain transfer in the background.
You didn't have to wait for blockchain confirmation. The cryptographic signature was proof enough.
Check Your Payment History
See what you've spent:
x402 history
Or check the Base block explorer directly. Go to basescan.org, paste your wallet address, and look at the USDC transfers.
Every payment is onchain and auditable.
Troubleshooting
"Insufficient balance"
You need USDC on Base, not ETH, not USDC on Ethereum, not anything else. Check:
- You're on Base network (chain ID 8453)
- You have USDC (not USD, not USDbC)
- Balance is enough for the payment + a tiny bit extra
"Invalid signature"
Usually means:
- Wrong private key
- Wrong network configured
- Payment expired (they're valid for ~5 minutes)
Try again — payments have short expiry windows.
"Network error"
The API or facilitator might be temporarily down. Wait a minute and retry.
Payment went through but no data
The API returned a task_id. You need to poll for the result:
curl https://api.agentutil.dev/v1/tasks/YOUR_TASK_ID
What's Next?
Give Your AI Agent a Wallet
The real power of x402 is autonomous payments. Your AI agent can have its own wallet and pay for APIs without human intervention.
See: Setting Up an x402 Wallet for Your AI Agent
Build Your Own x402 API
Want to accept x402 payments? It's easier than you think.
Understand the Protocol
Dive deeper into how x402 works under the hood.
See: How x402 Works
Quick Reference
| Tool | Endpoint | Price |
|---|---|---|
| Email verification | /v1/tools/email.verify/tasks | $0.01 |
| IP geolocation | /v1/tools/ip.geolocate/tasks | $0.005 |
| Geocoding | /v1/tools/geo.locate/tasks | $0.005 |
| DNS lookup | /v1/tools/dns.lookup/tasks | $0.002 |
| URL status | /v1/tools/url.status/tasks | $0.002 |
Base URL: https://api.agentutil.dev
You did it. Your first x402 payment. No account, no API key, no invoice — just crypto and an API call. Welcome to the future of machine-to-machine payments.
Questions? Email silas@agentutil.dev