Autonomous Agent Payments
Coal enables AI agents to pay for products and services autonomously — real USDC on Base, no human interaction needed.
How It Works
- Agent has a wallet — funded with USDC on Base (via Privy server wallet or raw key)
- Agent discovers — browses merchants via the Discovery API
- Agent pays — sends USDC on-chain, confirms with Coal API
- Agent verifies — receipt published to 0G Storage, anchored on 0G Chain
Agent Wallet Setup
Privy Server Wallets (Recommended)
Coal uses Privy server wallets for agent wallets. Keys are secured in TEE enclaves — never exposed.
typescript
1// Create a server wallet (one-time)2const wallet = await privy.wallets.create({ chain_type: 'ethereum' });3// wallet.address = "0x99301e..."45// Send USDC via the wallet6const tx = await privy.wallets.rpc(wallet.id, {7 method: 'eth_sendTransaction',8 caip2: 'eip155:8453', // Base mainnet9 params: { transaction: { to: USDC_ADDRESS, data: transferCalldata } }10});
Fund & Withdraw
- Fund: Send USDC on Base to the agent wallet address
- Withdraw: Agent can send remaining USDC to any address via
POST /api/agent/wallet/withdraw - Users can always withdraw — Privy wallets are self-custodial
Autonomous Payment Flow
Step 1: Check Balance
bash
1GET /api/agent/wallet2# → { "address": "0x993...", "balance": "14.20", "network": "base" }
Step 2: Create Checkout
bash
1POST /api/agent/checkout2{3 "amount": 0.10,4 "productName": "F1 Figurine",5 "currency": "USDC"6}7# → { "id": "cmn...", "amount": "0.10", "status": "pending" }
Step 3: Send USDC On-Chain
Agent sends a USDC ERC-20 transfer() to the merchant's payout address.
typescript
1const hash = await walletClient.writeContract({2 address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913', // USDC on Base3 abi: erc20Abi,4 functionName: 'transfer',5 args: [merchantPayoutAddress, parseUnits('0.10', 6)]6});
Step 4: Confirm Payment
bash
1POST /api/pay/confirm2{ "sessionId": "cmn...", "txHash": "0xabc...", "payerAddress": "0x993..." }3# → { "status": "verifying" }
Step 5: Verify Receipt
bash
1GET /api/receipts/{sessionId}2# → { "verified": true, "proofTrail": { "storage": {...}, "chain": {...} } }
The receipt includes a 3-step proof trail: Base TX → 0G Storage → 0G Chain anchor.
x402 Paywall Flow
For paywalled content, agents use the x402 protocol:
bash
1# 1. Check access → 402 with payment requirements2GET /api/paywalls/{id}/verify3# X-PAYMENT header contains: price, network, asset, payTo45# 2. Create pay intent6POST /api/agent/paywalls/{id}/pay-intent7# → { "checkoutId": "cmn...", "amount": 0.10 }89# 3. Pay + confirm (same as above)1011# 4. Re-check → 200 with content12GET /api/paywalls/{id}/verify?address=0x993...
Security
| Protection | How |
|---|---|
| Per-tx cap | $5 max enforced in wallet code |
| Rate limit | 10 payments/minute |
| Balance check | Fails fast if insufficient USDC |
| User confirmation | Agent asks before spending > $0.50 |
| Privy policies | Allowlisted recipients, daily caps |
Coal Agent SDK Tools
The coal-agent example app provides these OpenAI function-calling tools:
| Tool | Description |
|---|---|
discover_merchants | Browse marketplace for merchants/products/paywalls |
get_agent_wallet | Check wallet address and USDC balance |
execute_payment | Send real USDC autonomously (max $5) |
check_paywall | Check x402 paywall access status |
create_checkout | Create a payment session |
verify_receipt | Get 0G proof trail for a payment |
Live Demo
Try the Coal Agent Demo — click "Buy me something under $1" to see autonomous payments in action.
