DEV Community

Cover image for # Give Your AI Agent a Wallet — Autonomous USDC Payments in 10 Minutes
Wayne van der Merwe
Wayne van der Merwe

Posted on

# Give Your AI Agent a Wallet — Autonomous USDC Payments in 10 Minutes

AI agents are getting good at reasoning, planning, and executing tasks. But there's one thing they still can't do without a human in the loop: pay for things.

Most payment infrastructure assumes a human is making the purchase. Credit cards need CVVs. Bank transfers need approvals. OAuth flows need someone to click "Allow". None of that works when your agent needs to autonomously pay for a web scraping API at 3am, or split a task cost with another agent in a pipeline.

This tutorial shows you how to give any AI agent a real wallet with real money, spend controls, and the ability to pay merchants and other agents — all via a simple REST API.


What We're Building

By the end of this tutorial your agent will be able to:

  • Check its own USDC balance
  • Discover available merchants
  • Pay a merchant autonomously
  • Transfer USDC to another agent

We'll use Walleteer — payment infrastructure built specifically for AI agents. It handles wallet custody (AWS KMS), Solana payments, and spend policies so you don't have to.


How It Works

The model is simple:

  1. Humans register, create agent wallets, set spend policies, and fund them via Stripe
  2. Agents authenticate with an API key and pay autonomously within their policy
Human                          Agent
  │                              │
  ├─ Register & KYC              │
  ├─ Create agent wallet         │
  ├─ Set spend policy            │
  │  (max $10/tx, AgentToMerchant only)
  ├─ Fund via Stripe ($50 USDC)  │
  │                              │
  │                    ┌─────────┴──────────┐
  │                    │  Agent runs task   │
  │                    │  Needs to pay $1   │
  │                    │  for data API      │
  │                    └─────────┬──────────┘
  │                              │
  │                    POST /agent/payments/merchant
  │                    X-Agent-Key: wlt_live_...
  │                              │
  │                    ← 202 Accepted
  │                    ← Solana tx confirmed in ~3s
Enter fullscreen mode Exit fullscreen mode

Payments settle on Solana in ~3 seconds at near-zero cost. Platform fee is $0.05 per transaction, flat.


Step 1 — Register and Create an Agent Wallet

Go to app.walleteer.ai and sign up. Once logged in:

  1. Navigate to AgentsCreate Agent
  2. Give it a name (e.g. "Research Agent")
  3. Set a Spend Policy:
    • Max transaction amount: 10 USDC
    • Allowed corridors: Agent To Merchant, Agent To Agent
  4. Go to PaymentsFund Wallet and add some USDC via Stripe
  5. Copy the agent's API Key from the agent detail page

Your API key looks like this:

wlt_live_8c4a6407-2635-401d-8ef7-eaed31d1973f_a3x9k2m...
Enter fullscreen mode Exit fullscreen mode

Step 2 — Check Your Agent's Balance

curl https://api.walleteer.ai/agent/balance \
  -H "X-Agent-Key: wlt_live_YOUR_KEY_HERE"
Enter fullscreen mode Exit fullscreen mode

Response:

{
  "amount": 10.00,
  "currency": "USDC"
}
Enter fullscreen mode Exit fullscreen mode

In Python:

import httpx

AGENT_KEY = "wlt_live_YOUR_KEY_HERE"
BASE_URL = "https://api.walleteer.ai"

headers = {"X-Agent-Key": AGENT_KEY}

response = httpx.get(f"{BASE_URL}/agent/balance", headers=headers)
balance = response.json()
print(f"Balance: {balance['amount']} {balance['currency']}")
# Balance: 10.00 USDC
Enter fullscreen mode Exit fullscreen mode

In Node.js:

const AGENT_KEY = "wlt_live_YOUR_KEY_HERE";
const BASE_URL = "https://api.walleteer.ai";

const response = await fetch(`${BASE_URL}/agent/balance`, {
  headers: { "X-Agent-Key": AGENT_KEY }
});
const balance = await response.json();
console.log(`Balance: ${balance.amount} ${balance.currency}`);
// Balance: 10.00 USDC
Enter fullscreen mode Exit fullscreen mode

Step 3 — Discover Merchants

Before paying, your agent can discover available merchants:

response = httpx.get(f"{BASE_URL}/merchants", headers=headers)
merchants = response.json()

for merchant in merchants:
    print(f"{merchant['name']} — code: {merchant['merchantCode']}")
Enter fullscreen mode Exit fullscreen mode

Each merchant has a unique merchantCode your agent uses to identify who to pay.


Step 4 — Make a Payment

import uuid

payment = httpx.post(
    f"{BASE_URL}/agent/payments/merchant",
    headers={**headers, "Content-Type": "application/json"},
    json={
        "merchantCode": "DATAAPI01",
        "amount": 1.00,
        "currency": "USDC",
        "idempotencyKey": str(uuid.uuid4()),  # unique per payment attempt
        "itemizedDetails": "web_scrape:url=example.com"
    }
)

result = payment.json()
print(f"Payment {result['status']} — tx: {result['transactionId']}")
# Payment Completed — tx: f81eb8ef-b99a-4548-...
Enter fullscreen mode Exit fullscreen mode

The payment settles on Solana in ~3 seconds. The idempotencyKey prevents double payments on retry — always generate a unique key per payment attempt and persist it before submitting.


Step 5 — Pay Another Agent

In multi-agent pipelines, agents often need to pay each other for subtasks:

# Agent A pays Agent B for completing a research subtask
payment = httpx.post(
    f"{BASE_URL}/agent/payments/agent",
    headers={**headers, "Content-Type": "application/json"},
    json={
        "recipientAgentId": "af9669b2-f3ee-4d94-8cdc-510afc6a3f9c",
        "amount": 0.50,
        "currency": "USDC",
        "idempotencyKey": str(uuid.uuid4())
    }
)
Enter fullscreen mode Exit fullscreen mode

The recipient can also be a raw Solana public key for payments to external wallets.


Step 6 — Integrate Into Your Agent Loop

Here's how to wire this into a real agent decision loop:

import httpx
import uuid

class WalleteerClient:
    def __init__(self, agent_key: str):
        self.headers = {
            "X-Agent-Key": agent_key,
            "Content-Type": "application/json"
        }
        self.base_url = "https://api.walleteer.ai"

    def get_balance(self) -> float:
        r = httpx.get(f"{self.base_url}/agent/balance", headers=self.headers)
        return r.json()["amount"]

    def pay_merchant(self, merchant_code: str, amount: float, details: str = "") -> dict:
        r = httpx.post(
            f"{self.base_url}/agent/payments/merchant",
            headers=self.headers,
            json={
                "merchantCode": merchant_code,
                "amount": amount,
                "currency": "USDC",
                "idempotencyKey": str(uuid.uuid4()),
                "itemizedDetails": details
            }
        )
        r.raise_for_status()
        return r.json()


# In your agent loop
wallet = WalleteerClient("wlt_live_YOUR_KEY_HERE")

def run_agent_task(task: str):
    # Check balance before spending
    balance = wallet.get_balance()
    if balance < 1.0:
        raise ValueError("Insufficient balance — human needs to top up")

    # Agent decides it needs data
    print("Fetching research data...")
    payment = wallet.pay_merchant(
        merchant_code="DATAAPI01",
        amount=1.00,
        details=f"task:{task}"
    )
    print(f"Paid $1.00 USDC — {payment['status']}")

    # Continue with task using the paid-for data
    # ...
Enter fullscreen mode Exit fullscreen mode

Spend Policies — Keeping Agents Safe

This is the part that makes autonomous payments actually safe to deploy. Every agent has a spend policy set by the human owner:

Max transaction amount: $10 USDC
Allowed corridors: AgentToMerchant, AgentToAgent
Daily limit: (coming soon)
Enter fullscreen mode Exit fullscreen mode

If an agent tries to exceed its policy, the API returns 403 Forbidden. The agent can never spend more than you've allowed — even if it's been prompt-injected or goes rogue.


Receiving Payments as a Merchant

If you're building a service that AI agents will pay for, set up a merchant webhook:

from flask import Flask, request
import hmac
import hashlib

app = Flask(__name__)
WEBHOOK_SECRET = "your-webhook-secret"

@app.route("/webhooks/walleteer", methods=["POST"])
def handle_payment():
    # Verify signature
    sig = request.headers.get("X-Walleteer-Signature", "")
    expected = "sha256=" + hmac.new(
        WEBHOOK_SECRET.encode(),
        request.data,
        hashlib.sha256
    ).hexdigest()

    if not hmac.compare_digest(expected, sig):
        return "Forbidden", 403

    payload = request.get_json()
    if payload["event"] == "payment.completed":
        order_id = payload["orderId"]
        amount = payload["amount"]
        print(f"Received {amount} USDC for order {order_id}")
        fulfill_order(order_id)

    return "", 200
Enter fullscreen mode Exit fullscreen mode

Walleteer delivers the webhook within milliseconds of on-chain settlement. See the full webhook docs for the complete payload schema and signature verification examples in Node.js.


What's Next

  • API docs: docs.walleteer.ai
  • Dashboard: app.walleteer.ai
  • Transaction history: GET /agent/transactions — your agent can query its own payment history
  • Balance alerts: Walleteer notifies you when your agent's reserve drops below a threshold

The agentic economy is coming. Agents that can pay their own way — and get paid for their work — are going to be dramatically more useful than ones that need a human credit card every time they need a resource.


Built something cool with Walleteer? Drop a comment below — I'd love to see what agents people are building.

Top comments (0)