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
- Isolated funds: Agent can only spend what you transfer to it
- Encrypted storage: Private key is encrypted in browser localStorage
- Budget cap: Default $0.75, maximum $5.00
- Withdrawal: You can retrieve remaining funds anytime
Step-by-Step: Creating an Autonomous Agent
Step 1: Navigate to Autonomous Agents
- Open the starter kit at
http://localhost:3000 - Click the "AI Agent" tab
- Select "Autonomous-Agents" from the sub-navigation
Step 2: Connect Your Main Wallet
- Click "Connect Wallet"
- Ensure you're on Avalanche Fuji Testnet
- Your wallet address appears in the header
Step 3: Create Agent Wallet
- In the Authorization Panel, click "Create Agent Wallet"
- A new wallet address is generated
- 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
- Enter a budget amount (e.g., $0.75 USDC)
- Click "Fund Agent"
- Sign the transaction in your main wallet
- 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:
- Type a command like "price of ETH" or "market summary"
- Click Send - no wallet popup appears
- The agent signs the payment automatically using its private key
- 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:
- Click "Withdraw" in the Authorization Panel
- Enter the amount to withdraw (or click "Max")
- The agent signs a transfer back to your main wallet
- Your main wallet receives the remaining USDC
Smart Commands
The agent understands various commands:
| Command | Action | Cost |
|---|---|---|
| "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
- Fund conservatively: Only transfer what you plan to use
- Withdraw when done: Don't leave large balances in agent wallets
- Use testnet first: Always test on Fuji before mainnet
- 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.
Is this guide helpful?
