Hardware Update: Use NVMe SSD by Jan 17

Autonomous AI Agent

Build an AI agent that makes payments independently without user confirmation.

What Makes an Agent Autonomous?

In the previous lesson, you still had to sign each payment manually. A truly autonomous agent operates without any user interaction per transaction:

  • No wallet popups for each payment
  • Pre-authorized budget limits spending
  • Independent operation - the agent decides when to pay

This is achieved by giving the agent its own wallet with a limited budget.

Agent Wallet Architecture

The autonomous agent system creates a dedicated wallet separate from your main wallet:

Your Main Wallet                 Agent Wallet
┌─────────────────┐             ┌─────────────────┐
│ Your funds      │  Fund →     │ Limited budget  │
│ You control     │             │ Agent controls  │
│ Signs manually  │             │ Signs auto      │
└─────────────────┘  ← Withdraw └─────────────────┘

Security Model

  1. Isolated funds: Agent can only spend what you transfer to it
  2. Encrypted storage: Private key is encrypted in browser localStorage
  3. Budget cap: Default $0.75, maximum $5.00
  4. Withdrawal: You can retrieve remaining funds anytime

Step-by-Step: Creating an Autonomous Agent

Step 1: Navigate to Autonomous Agents

  1. Open the starter kit at http://localhost:3000
  2. Click the "AI Agent" tab
  3. Select "Autonomous-Agents" from the sub-navigation

Step 2: Connect Your Main Wallet

  1. Click "Connect Wallet"
  2. Ensure you're on Avalanche Fuji Testnet
  3. Your wallet address appears in the header

Step 3: Create Agent Wallet

  1. In the Authorization Panel, click "Create Agent Wallet"
  2. A new wallet address is generated
  3. The private key is encrypted and stored in your browser

The agent wallet starts with zero balance - it cannot spend anything yet.

Step 4: Fund the Agent

  1. Enter a budget amount (e.g., $0.75 USDC)
  2. Click "Fund Agent"
  3. Sign the transaction in your main wallet
  4. USDC transfers from your wallet to the agent wallet

The agent is now authorized to spend up to your funded amount.

Step 5: Query Cryptocurrency Prices

With the agent funded, you can now use it autonomously:

  1. Type a command like "price of ETH" or "market summary"
  2. Click Send - no wallet popup appears
  3. The agent signs the payment automatically using its private key
  4. Price data is fetched and displayed

Each query costs $0.02 USDC for the cryptocurrency price lookup service.

Step 6: Observe Autonomous Payments

Watch the Service Network panel:

  • Each successful call shows the service used
  • Payment amount ($0.02) is displayed
  • Agent's remaining balance updates automatically

The agent made payments without any manual confirmation from you.

Step 7: Withdraw Remaining Funds

When you're done:

  1. Click "Withdraw" in the Authorization Panel
  2. Enter the amount to withdraw (or click "Max")
  3. The agent signs a transfer back to your main wallet
  4. Your main wallet receives the remaining USDC

Smart Commands

The agent understands various commands:

CommandActionCost
"price of ETH"Single crypto price$0.02
"price of BTC, AVAX"Multiple prices$0.02 each
"market summary"Top 3 cryptos$0.06 total
"top coins"Top 5 cryptos$0.10 total

The agent parses your request and makes the appropriate number of paid API calls.

Security Considerations

Browser Storage

The agent's private key is stored in browser localStorage:

  • Encrypted using your wallet address as the encryption key
  • Session-bound - clearing browser data removes the wallet
  • Single device - the agent only exists on the browser where created

Best Practices

  1. Fund conservatively: Only transfer what you plan to use
  2. Withdraw when done: Don't leave large balances in agent wallets
  3. Use testnet first: Always test on Fuji before mainnet
  4. Clear data carefully: Clearing browser storage deletes the agent wallet

What the Agent Cannot Do

  • Access your main wallet's private key
  • Spend more than its funded balance
  • Operate on a different device/browser

Real-World Applications

This autonomous agent pattern enables:

  • AI assistants that pay for premium data sources
  • Trading bots that pay for real-time market data
  • Research agents that access paid APIs independently
  • Automation workflows that operate without human supervision

The x402 protocol makes these autonomous payments possible with blockchain security and transparency.

Loading...

Is this guide helpful?