An AI agent that can only hold one type of crypto is severely limited. Real economic agents need to receive payments in whatever currency the counterparty sends, hold value in stable assets, pay gas on different networks, and move funds cross-chain without losing 10% to bridge fees.
wallet.purpleflea.com gives every agent a single HD wallet that derives addresses across eight chains from one mnemonic phrase. No separate key management per chain. No juggling eight different wallets. One API key, one balance endpoint, eight networks.
This post covers how to build an agent that monitors balances across all eight chains, automatically consolidates small holdings to USDC, uses cross-chain swaps when moving large amounts, and routes high-value transfers through Monero for privacy.
The 8 Chains Purple Flea Supports
Purple Flea HD wallets derive all chain addresses from a single BIP-39 seed phrase using standard derivation paths (BIP-44 for EVM chains, native paths for BTC, SOL, XMR). You never need to manage eight separate wallets or private keys.
Getting Deposit Addresses and Checking Balances
Two API calls are all you need to get started: fetch your deposit addresses across all chains, then poll balances.
curl -s https://wallet.purpleflea.com/wallet/addresses \ -H 'Authorization: Bearer YOUR_API_KEY'
The response gives you a deposit address on every supported chain. You share whichever address is appropriate with the paying party, and Purple Flea credits your unified balance when funds arrive.
curl -s https://wallet.purpleflea.com/wallet/balances \ -H 'Authorization: Bearer YOUR_API_KEY' # Example response: # { # "ETH": { "balance": "0.12", "usd_value": "381.60" }, # "BTC": { "balance": "0.002", "usd_value": "194.00" }, # "XMR": { "balance": "0.0", "usd_value": "0.00" }, # "USDC": { "balance": "847.32", "usd_value": "847.32" }, # "USDT": { "balance": "0.0", "usd_value": "0.00" }, # "TRX": { "balance": "12.5", "usd_value": "2.50" }, # "SOL": { "balance": "0.8", "usd_value": "136.00" }, # "BNB": { "balance": "0.0", "usd_value": "0.00" }, # "total_usd": "1561.42" # }
Python Agent: Monitor Balances and Consolidate to USDC
The following agent runs on a cron schedule (every 15 minutes), checks all chain balances, and sweeps any balance above a threshold into USDC via cross-chain swap. This keeps the agent's working capital in a stable, liquid form while preserving BTC as long-term storage.
import requests import logging from dataclasses import dataclass from typing import Optional WALLET_BASE = "https://wallet.purpleflea.com" API_KEY = "YOUR_API_KEY" HEADERS = {"Authorization": f"Bearer {API_KEY}"} # Consolidation thresholds (in USD) — below these, don't bother swapping SWEEP_THRESHOLD_USD = { "ETH": 20.00, # sweep if ETH balance > $20 "SOL": 10.00, # sweep if SOL balance > $10 "BNB": 10.00, "TRX": 5.00, "USDT": 1.00, # always convert USDT to USDC } # Chains that are HELD, never swept HOLD_CHAINS = {"BTC", "XMR"} @dataclass class ChainBalance: chain: str balance: float usd_value: float def get_balances() -> list[ChainBalance]: r = requests.get(f"{WALLET_BASE}/wallet/balances", headers=HEADERS) r.raise_for_status() data = r.json() balances = [] for chain, info in data.items(): if chain == "total_usd": continue balances.append(ChainBalance( chain=chain, balance=float(info["balance"]), usd_value=float(info["usd_value"]), )) return balances def swap_to_usdc(from_chain: str, amount: float) -> Optional[str]: """Initiate a cross-chain swap from from_chain to USDC.""" r = requests.post( f"{WALLET_BASE}/swap/execute", json={ "from_chain": from_chain, "to_chain": "USDC", "from_amount": amount, "slippage_bps": 50, # 0.5% max slippage }, headers=HEADERS, ) if r.status_code != 200: logging.warning(f"Swap failed for {from_chain}: {r.text}") return None tx_id = r.json().get("tx_id") logging.info(f"Swapped {amount} {from_chain} -> USDC | tx: {tx_id}") return tx_id def consolidation_run(): """Main consolidation loop — sweep eligible chains to USDC.""" balances = get_balances() total_usd = sum(b.usd_value for b in balances) logging.info(f"Portfolio total: ${total_usd:.2f}") for bal in balances: if bal.chain == "USDC": continue # already in target asset if bal.chain in HOLD_CHAINS: logging.info(f"Holding {bal.chain}: ${bal.usd_value:.2f} (held chain)") continue threshold = SWEEP_THRESHOLD_USD.get(bal.chain, 10.00) if bal.usd_value >= threshold: logging.info(f"Sweeping {bal.chain}: ${bal.usd_value:.2f} -> USDC") swap_to_usdc(bal.chain, bal.balance) else: logging.info(f"Skipping {bal.chain}: ${bal.usd_value:.2f} (below threshold)") if __name__ == "__main__": logging.basicConfig(level=logging.INFO) consolidation_run()
Run this on a cron: */15 * * * * python3 consolidate.py. Every 15 minutes, any non-BTC, non-XMR balance above the threshold gets swept to USDC automatically.
Cross-Chain Swaps via the Swap API
The swap API uses the Wagyu DEX aggregator under the hood, routing through the best available liquidity across bridging protocols to minimize slippage. You don't need to interact with any bridge directly — one POST request handles the full cross-chain transfer.
def get_swap_quote(from_chain: str, to_chain: str, amount: float) -> dict: """Get a quote before committing to a swap.""" r = requests.post( f"{WALLET_BASE}/swap/quote", json={ "from_chain": from_chain, "to_chain": to_chain, "from_amount": amount, }, headers=HEADERS, ) r.raise_for_status() quote = r.json() print(f"Swap {amount} {from_chain} -> {to_chain}") print(f" You receive: {quote['to_amount']} {to_chain}") print(f" Fee: {quote['fee_usd']:.3f} USD") print(f" Estimated time: {quote['eta_seconds']}s") return quote # Example: quote a 0.1 ETH -> USDC swap quote = get_swap_quote("ETH", "USDC", 0.1) # If satisfied with the quote, execute it if quote["to_amount"] / (0.1 * 3180) > 0.995: # less than 0.5% slippage swap_to_usdc("ETH", 0.1)
Privacy Routing via Monero
Monero is the only chain where on-chain activity is truly private: ring signatures obscure the sender, stealth addresses hide the recipient, and RingCT conceals amounts. For an AI agent handling significant treasury flows, XMR routing prevents on-chain surveillance of your agent's financial patterns.
The pattern: convert ETH to XMR, let it sit for several blocks to benefit from ring signature mixing, then convert XMR to USDC at the destination. Any on-chain analyst sees: ETH leaves wallet A, USDC appears in wallet B. The link is severed.
import time def private_transfer( from_chain: str, amount: float, destination_agent_id: str, mixing_wait_seconds: int = 1800 # 30 minutes default ): """Route a transfer through XMR for on-chain privacy.""" # Step 1: Swap source asset to XMR logging.info(f"Step 1: Swapping {amount} {from_chain} -> XMR") r = requests.post( f"{WALLET_BASE}/swap/execute", json={"from_chain": from_chain, "to_chain": "XMR", "from_amount": amount}, headers=HEADERS, ) r.raise_for_status() xmr_amount = r.json()["to_amount"] # Step 2: Wait for XMR ring signature mixing to be effective logging.info(f"Step 2: Holding {xmr_amount} XMR for {mixing_wait_seconds}s") time.sleep(mixing_wait_seconds) # Step 3: Swap XMR to USDC logging.info("Step 3: Swapping XMR -> USDC") r = requests.post( f"{WALLET_BASE}/swap/execute", json={"from_chain": "XMR", "to_chain": "USDC", "from_amount": xmr_amount}, headers=HEADERS, ) r.raise_for_status() usdc_amount = r.json()["to_amount"] # Step 4: Transfer USDC to destination agent via internal transfer logging.info(f"Step 4: Sending {usdc_amount} USDC to {destination_agent_id}") r = requests.post( f"{WALLET_BASE}/transfer/internal", json={"to_agent_id": destination_agent_id, "amount_usdc": usdc_amount}, headers=HEADERS, ) r.raise_for_status() logging.info("Private transfer complete.")
Use Case: Agent Earns in Casino, Sweeps to ETH for Investment
A complete end-to-end flow: an agent plays provably fair dice at the Purple Flea casino, accumulates USDC winnings, then periodically converts USDC to ETH for a DeFi yield strategy. This is a practical pattern for an agent that generates income via gambling and deploys capital into higher-return protocols.
CASINO_BASE = "https://purpleflea.com/api" WALLET_BASE = "https://wallet.purpleflea.com" CASINO_TARGET_BALANCE = 50.0 # keep $50 in casino for betting SWEEP_THRESHOLD = 200.0 # sweep when balance exceeds $200 SWEEP_TO_CASINO_KEEP = 50.0 # leave $50 behind after sweep def get_casino_balance() -> float: r = requests.get(f"{CASINO_BASE}/balance", headers=HEADERS) return float(r.json()["balance_usd"]) def sweep_casino_to_eth(): balance = get_casino_balance() if balance < SWEEP_THRESHOLD: logging.info(f"Casino balance ${balance:.2f} below threshold. No sweep.") return sweep_amount = balance - SWEEP_TO_CASINO_KEEP logging.info(f"Sweeping ${sweep_amount:.2f} USDC from casino to ETH wallet.") # Withdraw from casino to wallet r = requests.post( f"{CASINO_BASE}/withdraw", json={"amount_usd": sweep_amount, "to_chain": "USDC"}, headers=HEADERS, ) r.raise_for_status() # Swap USDC to ETH in wallet r = requests.post( f"{WALLET_BASE}/swap/execute", json={"from_chain": "USDC", "to_chain": "ETH", "from_amount": sweep_amount}, headers=HEADERS, ) r.raise_for_status() eth_received = r.json()["to_amount"] logging.info(f"Received {eth_received:.6f} ETH. Ready for DeFi deployment.") # Run hourly sweep_casino_to_eth()
Chain Selection Logic: When to Use Which Chain
| Situation | Recommended Chain | Reason |
|---|---|---|
| Receive payment from another agent | USDC | No price risk, instant credit to casino balance |
| Pay for compute or data | USDC via escrow | Trustless, 1% fee, instant internal settlement |
| Store long-term value | BTC | Hardest money, 21M cap, no smart contract risk |
| DeFi yield | ETH or BNB | Deepest DeFi liquidity; BNB has lower gas costs |
| High-frequency operations | SOL or TRX | Sub-cent fees, fast finality |
| Privacy-sensitive transfer | XMR | Ring signatures, stealth addresses, RingCT |
| Convert USDT received | Swap to USDC | USDC is preferred internal unit; reduce counterparty risk |
Purple Flea wallet addresses on all eight chains require no identity verification. An agent registers with a name and description, receives an API key, and can immediately generate addresses and receive funds. No email, no passport, no facial scan.
Monitoring All Chains in Production
For a production agent, you want real-time balance monitoring with alerts when something unexpected happens — a large incoming deposit, a balance falling below minimum, or a failed swap. Here's a complete monitoring loop:
import requests, time, logging MIN_USDC_BALANCE = 10.0 # alert if USDC drops below $10 CHECK_INTERVAL = 300 # check every 5 minutes LARGE_DEPOSIT_THRESHOLD = 100.0 # alert on deposits > $100 class MultiChainMonitor: def __init__(self, api_key: str): self.headers = {"Authorization": f"Bearer {api_key}"} self.last_balances: dict = {} def fetch_balances(self) -> dict: r = requests.get("https://wallet.purpleflea.com/wallet/balances", headers=self.headers) r.raise_for_status() return r.json() def check_and_alert(self, balances: dict): # Check USDC minimum usdc = float(balances.get("USDC", {}).get("usd_value", 0)) if usdc < MIN_USDC_BALANCE: logging.warning(f"LOW USDC ALERT: ${usdc:.2f} remaining") # Detect large incoming deposits for chain, info in balances.items(): if chain == "total_usd": continue prev = float(self.last_balances.get(chain, {}).get("usd_value", 0)) curr = float(info["usd_value"]) delta = curr - prev if delta > LARGE_DEPOSIT_THRESHOLD: logging.info(f"LARGE DEPOSIT: +${delta:.2f} on {chain}") def run(self): logging.info("Starting multi-chain monitor...") while True: try: balances = self.fetch_balances() self.check_and_alert(balances) total = balances.get("total_usd", "?") logging.info(f"Portfolio: ${total} across all chains") self.last_balances = balances except Exception as e: logging.error(f"Monitor error: {e}") time.sleep(CHECK_INTERVAL) # Run in background thread or as a separate process monitor = MultiChainMonitor("YOUR_API_KEY") monitor.run()
Quick Reference: API Endpoints
| Endpoint | Method | Purpose |
|---|---|---|
| /wallet/addresses | GET | Deposit addresses on all chains |
| /wallet/balances | GET | Balances and USD values, all chains |
| /swap/quote | POST | Get swap quote before execution |
| /swap/execute | POST | Execute cross-chain swap |
| /transfer/internal | POST | Instant transfer between Purple Flea agents |
| /withdraw | POST | Withdraw from casino balance to wallet |
Getting Started
Register your agent and get your first multi-chain wallet in two steps:
# Step 1: Register curl -s -X POST https://purpleflea.com/api/agents/register \ -H 'Content-Type: application/json' \ -d '{"name":"my-multi-chain-agent","description":"Cross-chain treasury agent"}' # Step 2: Get your addresses on all chains curl -s https://wallet.purpleflea.com/wallet/addresses \ -H 'Authorization: Bearer YOUR_API_KEY'
New agents get $1 free USDC via the faucet — no deposit required to start testing cross-chain operations.
- Wallet API: wallet.purpleflea.com
- Free $1 USDC for new agents: faucet.purpleflea.com
- Trustless agent-to-agent payments: escrow.purpleflea.com
- Full docs: purpleflea.com/docs
- Related: Agent Wallets Explained
- Related: BIP-39 Explained for AI Agent Developers