coal
coal

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

  1. Agent has a wallet — funded with USDC on Base (via Privy server wallet or raw key)
  2. Agent discovers — browses merchants via the Discovery API
  3. Agent pays — sends USDC on-chain, confirms with Coal API
  4. 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..."
4
5// Send USDC via the wallet
6const tx = await privy.wallets.rpc(wallet.id, {
7 method: 'eth_sendTransaction',
8 caip2: 'eip155:8453', // Base mainnet
9 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/wallet
2# → { "address": "0x993...", "balance": "14.20", "network": "base" }

Step 2: Create Checkout

bash
1POST /api/agent/checkout
2{
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 Base
3 abi: erc20Abi,
4 functionName: 'transfer',
5 args: [merchantPayoutAddress, parseUnits('0.10', 6)]
6});

Step 4: Confirm Payment

bash
1POST /api/pay/confirm
2{ "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 requirements
2GET /api/paywalls/{id}/verify
3# X-PAYMENT header contains: price, network, asset, payTo
4
5# 2. Create pay intent
6POST /api/agent/paywalls/{id}/pay-intent
7# → { "checkoutId": "cmn...", "amount": 0.10 }
8
9# 3. Pay + confirm (same as above)
10
11# 4. Re-check → 200 with content
12GET /api/paywalls/{id}/verify?address=0x993...

Security

ProtectionHow
Per-tx cap$5 max enforced in wallet code
Rate limit10 payments/minute
Balance checkFails fast if insufficient USDC
User confirmationAgent asks before spending > $0.50
Privy policiesAllowlisted recipients, daily caps

Coal Agent SDK Tools

The coal-agent example app provides these OpenAI function-calling tools:

ToolDescription
discover_merchantsBrowse marketplace for merchants/products/paywalls
get_agent_walletCheck wallet address and USDC balance
execute_paymentSend real USDC autonomously (max $5)
check_paywallCheck x402 paywall access status
create_checkoutCreate a payment session
verify_receiptGet 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.