An AI agent that can only read and write text is limited. The next generation of agents interact with the real world — and that includes money.
In this tutorial, you'll build a Python agent that:
- Creates its own HD wallet (works on 9 chains)
- Checks balances across Ethereum, Base, Polygon, Solana, and more
- Gets live crypto prices for 500+ tokens
- Stores its private key in an encrypted vault
All with one API key. No blockchain libraries, no node providers, no wallet SDKs. Just REST calls.
Why AI Agents Need Wallets
Think about it: if your agent can browse the web, write code, and send emails — why can't it manage money?
Use cases for wallet-enabled agents:
- Portfolio monitoring — Track balances across chains, alert on large movements
- DeFi automation — Rebalance positions, claim rewards, execute swaps
- Payment agents — Receive payments, auto-settle to stablecoins
- Treasury management — Prepare transactions for human approval
- Research bots — Monitor on-chain activity, analyze whale movements
Architecture
Your AI Agent (Python / Node.js / any language)
|
| REST API calls (Bearer token auth)
v
Agent Gateway (single API key, 200 free credits)
|
+----+----+--------+-----------+
| | | |
Wallet Prices Secrets 38 more
API API Vault services
| |
ETH SOL Binance
BSC ARB CoinGecko
BASE ... Kraken
Your agent talks to Agent Gateway. The gateway handles auth, rate limiting, and routing. You get 200 free credits on key creation — no email, no credit card.
Step 1: Get Your API Key (30 seconds)
One POST request. That's it.
curl -X POST https://agent-gateway-kappa.vercel.app/api/keys/create
Response:
{
"key": "gw_a1b2c3d4e5f6...",
"credits": 200,
"note": "200 free credits (expires in 30 days)."
}
Save this key. You'll use it as a Bearer token for all requests.
Step 2: Create an HD Wallet
Generate a hierarchical deterministic wallet:
curl -X POST https://agent-gateway-kappa.vercel.app/v1/agent-wallet/wallets/generate \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{}'
Response:
{
"mnemonic": "comic better connect left letter solid public random high chief heavy squirrel",
"addresses": {},
"warning": "STORE YOUR MNEMONIC SECURELY."
}
Now derive addresses across all supported chains:
curl -X POST https://agent-gateway-kappa.vercel.app/v1/agent-wallet/wallets/derive \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"mnemonic": "comic better connect left letter solid ...", "chain": "ethereum"}'
Response — one mnemonic, addresses on 7 chains:
{
"addresses": {
"ethereum": {"address": "0xc93E...6096", "derivation_path": "m/44'/60'/0'/0/0"},
"base": {"address": "0xc93E...6096", "derivation_path": "m/44'/60'/0'/0/0"},
"polygon": {"address": "0xc93E...6096", "derivation_path": "m/44'/60'/0'/0/0"},
"arbitrum": {"address": "0xc93E...6096", "derivation_path": "m/44'/60'/0'/0/0"},
"optimism": {"address": "0xc93E...6096", "derivation_path": "m/44'/60'/0'/0/0"},
"bsc": {"address": "0xc93E...6096", "derivation_path": "m/44'/60'/0'/0/0"},
"solana": {"address": "CGeZK...TfTg", "derivation_path": "m/44'/501'/0'/0'"}
},
"private_key": "0x6092..."
}
Security tip: Never log or hardcode the mnemonic or private key. We'll store them in a secrets vault in Step 4.
Supported Chains
EVM chains share one address: Ethereum, Polygon, Arbitrum, Optimism, Base, BSC. Solana gets its own address from the same seed.
Step 3: Check Balances
Query the native token balance on any chain:
# Check ETH balance on Ethereum
curl "https://agent-gateway-kappa.vercel.app/v1/agent-wallet/wallets/0x742d.../balance" \
-H "Authorization: Bearer YOUR_API_KEY"
# Check all chains at once
curl "https://agent-gateway-kappa.vercel.app/v1/agent-wallet/wallets/0x742d.../balance/all" \
-H "Authorization: Bearer YOUR_API_KEY"
Step 4: Store Private Keys Securely
Don't leave private keys in environment variables. Use the Secrets Vault:
curl -X POST "https://agent-gateway-kappa.vercel.app/v1/agent-secrets/api/secrets" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"key": "wallet_pk", "value": "0xYOUR_PRIVATE_KEY"}'
Retrieve later:
curl "https://agent-gateway-kappa.vercel.app/v1/agent-secrets/api/secrets/wallet_pk" \
-H "Authorization: Bearer YOUR_API_KEY"
All secrets are encrypted and scoped to your API key. No one else can access them.
Step 5: Get Live Crypto Prices
Real-time price feeds for 500+ tokens — no separate API key needed:
curl "https://agent-gateway-kappa.vercel.app/v1/crypto-feeds/api/prices" \
-H "Authorization: Bearer YOUR_API_KEY"
{
"BTCUSDT": {"price": 73004.20, "change_pct": 7.45},
"ETHUSDT": {"price": 2145.21, "change_pct": 9.22},
"SOLUSDT": {"price": 92.53, "change_pct": 9.79}
}
Get a specific token:
curl "https://agent-gateway-kappa.vercel.app/v1/crypto-feeds/api/price/ETH" \
-H "Authorization: Bearer YOUR_API_KEY"
Step 6: Complete Autonomous Portfolio Agent
Here's the full Python agent — copy, paste, and run:
import requests
import json
API = "https://agent-gateway-kappa.vercel.app"
def create_api_key():
"""Get a free API key with 200 credits."""
res = requests.post(f"{API}/api/keys/create")
data = res.json()
print(f"API Key: {data['key']}")
print(f"Credits: {data['credits']}")
return data["key"]
def create_wallet(api_key):
"""Generate a new HD wallet and derive addresses."""
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
# Step 1: Generate mnemonic
res = requests.post(
f"{API}/v1/agent-wallet/wallets/generate",
headers=headers, json={}
)
wallet = res.json()
mnemonic = wallet["mnemonic"]
# Step 2: Derive addresses on all chains
res = requests.post(
f"{API}/v1/agent-wallet/wallets/derive",
headers=headers,
json={"mnemonic": mnemonic, "chain": "ethereum"},
)
derived = res.json()
eth_addr = derived["addresses"]["ethereum"]["address"]
print(f"Wallet: {eth_addr}")
return {**wallet, **derived, "address": eth_addr}
def store_secret(api_key, key, value):
"""Store sensitive data in the encrypted vault."""
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json",
}
requests.post(
f"{API}/v1/agent-secrets/api/secrets",
headers=headers,
json={"key": key, "value": value},
)
print(f"Secret '{key}' stored securely")
def get_prices(api_key, symbols=None):
"""Fetch live crypto prices."""
headers = {"Authorization": f"Bearer {api_key}"}
res = requests.get(f"{API}/v1/crypto-feeds/api/prices", headers=headers)
prices = res.json()
if symbols:
return {k: v for k, v in prices.items() if k in symbols}
return prices
def get_balance(api_key, address):
"""Check wallet balance across all chains."""
headers = {"Authorization": f"Bearer {api_key}"}
res = requests.get(
f"{API}/v1/agent-wallet/wallets/{address}/balance/all",
headers=headers,
)
return res.json()
def run_agent():
print("=== Autonomous Portfolio Agent ===\n")
# 1. Get API key
api_key = create_api_key()
# 2. Create wallet
wallet = create_wallet(api_key)
# 3. Store private key securely (never in code!)
store_secret(api_key, "wallet_pk", wallet.get("privateKey", ""))
store_secret(api_key, "wallet_mnemonic", wallet.get("mnemonic", ""))
# 4. Get market prices
print("\n--- Market Prices ---")
watchlist = ["BTCUSDT", "ETHUSDT", "SOLUSDT", "MATICUSDT", "ARBUSDT"]
prices = get_prices(api_key, watchlist)
for symbol, data in prices.items():
if isinstance(data, dict):
price = data.get("price", "N/A")
change = data.get("change_pct", 0)
print(f" {symbol}: ${price:,.2f} ({change:+.1f}%)")
# 5. Check wallet balances
print(f"\n--- Wallet Balances ({wallet['address'][:10]}...) ---")
balances = get_balance(api_key, wallet["address"])
if isinstance(balances, dict):
for chain, bal in balances.items():
if bal and bal != "0":
print(f" {chain}: {bal}")
# 6. Check remaining credits
headers = {"Authorization": f"Bearer {api_key}"}
usage = requests.get(f"{API}/api/keys/balance", headers=headers).json()
print(f"\nCredits remaining: {usage.get('credits', 'N/A')}")
print("Done! Your agent now has its own wallet.")
if __name__ == "__main__":
run_agent()
Node.js Version
const API = "https://agent-gateway-kappa.vercel.app";
async function main() {
// 1. Get API key
const keyRes = await fetch(`${API}/api/keys/create`, { method: "POST" });
const { key } = await keyRes.json();
const headers = { Authorization: `Bearer ${key}` };
console.log(`API Key: ${key}`);
// 2. Create wallet
const genRes = await fetch(`${API}/v1/agent-wallet/wallets/generate`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: "{}",
});
const { mnemonic } = await genRes.json();
// 3. Derive addresses
const deriveRes = await fetch(`${API}/v1/agent-wallet/wallets/derive`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ mnemonic, chain: "ethereum" }),
});
const wallet = await deriveRes.json();
const address = wallet.addresses.ethereum.address;
console.log(`Wallet: ${address}`);
// 4. Store private key in secrets vault
await fetch(`${API}/v1/agent-secrets/api/secrets`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ key: "wallet_pk", value: wallet.private_key }),
});
// 5. Get crypto prices
const priceRes = await fetch(
`${API}/v1/crypto-feeds/api/prices`,
{ headers }
);
const prices = await priceRes.json();
Object.entries(prices).slice(0, 5).forEach(([sym, data]) => {
const p = data?.price ?? data;
console.log(` ${sym}: $${p}`);
});
// 6. Check balance
const balRes = await fetch(
`${API}/v1/agent-wallet/wallets/${address}/balance/all`,
{ headers }
);
console.log("Balances:", await balRes.json());
}
main().catch(console.error);
What's Next
You've just given an AI agent its own crypto wallet. Here's what else you can do with the same API key:
| Service | What It Does |
|---|---|
| Cross-chain Swaps | Swap tokens between chains via /v1/frostbyte-wallet/v1/swap/quote
|
| On-chain Analytics | Trending tokens, whale movements via /v1/onchain-analytics
|
| Agent Memory | Key-value storage + vector search via /v1/agent-memory
|
| Code Runner | Execute Python/Node.js/Bash in sandbox via /v1/agent-coderunner
|
| Task Scheduler | Cron-style scheduled jobs via /v1/agent-scheduler
|
| Web Scraper | Extract clean data from any URL via /v1/agent-scraper
|
All 40 services are available through one key. Browse the full catalog or check the getting started guide.
Built with Agent Gateway — 40 APIs, one key, 200 free credits.
Top comments (0)