Examples

Copy-paste scripts for AI agent integration

Examples

Ready-to-use scripts for AI agents. Change the variables at the top, copy-paste, and run.

Prerequisites for all examples: All write operations require an active session. Run these first:

export AW_MASTER_PASSWORD="your-password"
aw unlock --json

1. Send native token (ETH)

# Variables
WALLET="trading-agent"
TO="0x9f4E..."
AMOUNT="0.01"
 
# Execute
aw send --wallet $WALLET --to $TO --amount $AMOUNT --token ETH --json
 
Expected output:
{
  "ok": true,
  "data": {
    "tx_id": "tx_abc123...",
    "tx_hash": "0xdef456...",
    "status": "confirmed",
    "token": "ETH",
    "amount": "0.01",
    "to": "0x9f4E...",
    "chain": "Ethereum",
    "chain_id": 1,
    "explorer_url": "https://etherscan.io/tx/0xdef456..."
  }
}

2. Send ERC-20 token (USDC)

# Variables
WALLET="trading-agent"
TO="0x9f4E..."
AMOUNT="5"
 
# Execute
aw send --wallet $WALLET --to $TO --amount $AMOUNT --token USDC --json
 
Expected output:
{
  "ok": true,
  "data": {
    "tx_id": "tx_abc123...",
    "tx_hash": "0xdef456...",
    "status": "confirmed",
    "token": "USDC",
    "amount": "5",
    "to": "0x9f4E...",
    "chain": "Ethereum",
    "chain_id": 1,
    "explorer_url": "https://etherscan.io/tx/0xdef456..."
  }
}

3. Dry-run then execute

# Variables
WALLET="trading-agent"
TO="0x9f4E..."
AMOUNT="10"
TOKEN="USDC"
 
# Validate first (no transaction broadcast)
aw send --wallet $WALLET --to $TO --amount $AMOUNT --token $TOKEN --dry-run --json
 
# If ok, execute for real
aw send --wallet $WALLET --to $TO --amount $AMOUNT --token $TOKEN --json
 
Dry-run expected output:
{
  "ok": true,
  "data": {
    "tx_id": "tx_abc123...",
    "tx_hash": null,
    "status": "pending",
    "token": "USDC",
    "amount": "10",
    "to": "0x9f4E...",
    "chain": "Ethereum",
    "chain_id": 1,
    "dry_run": true
  }
}

4. Idempotent retry loop

# Variables
WALLET="trading-agent"
TO="0x9f4E..."
AMOUNT="5"
TOKEN="USDC"
KEY="tx-$(date +%s)"
 
# Retry up to 3 times with same idempotency key
for i in 1 2 3; do
  RESULT=$(aw send --wallet $WALLET --to $TO --amount $AMOUNT --token $TOKEN --idempotency-key $KEY --json 2>&1)
  OK=$(echo $RESULT | jq -r '.ok')
  if [ "$OK" = "true" ]; then
    echo "Success: $RESULT"
    break
  fi
  CODE=$(echo $RESULT | jq -r '.error.code')
  # Only retry on system errors, not business errors
  if [ "$CODE" != "ERR_RPC_UNAVAILABLE" ] && [ "$CODE" != "ERR_NEED_UNLOCK" ]; then
    echo "Non-retryable error: $RESULT"
    break
  fi
  echo "Attempt $i failed ($CODE), retrying..."
  sleep 2
done

5. Polymarket: approve → search → buy → check position

# Variables
WALLET="trading-agent"
 
# First-time only: approve Polymarket contracts (6 transactions)
aw predict approve-set --wallet $WALLET --json
 
# Search markets
aw predict markets -q "bitcoin" --limit 3 --json
 
# Buy position (replace MARKET_ID from search results)
MARKET_ID="0xfdc7..."
aw predict buy --wallet $WALLET --market $MARKET_ID --outcome yes --size 5 --price 0.62 --json
 
# Check positions
aw predict positions --wallet $WALLET --json

6. Full agent workflow (init → create → fund → trade)

# 1. Initialize
aw init --json
 
# 2. Unlock session
export AW_MASTER_PASSWORD="your-secure-password"
aw unlock --json
 
# 3. Create wallet
aw wallet create --name agent-01 --json
 
# 4. Get deposit address (fund with ETH + USDC on Ethereum, or any supported chain)
aw wallet deposit-address agent-01 --json
 
# 5. Check balance (after funding)
aw wallet balance agent-01 --json
 
# 6. Set spending policy
aw policy set agent-01 --limit-per-tx 10 --limit-daily 50 --max-tx-per-day 20 --json
 
# 7. Dry-run a transfer
aw send --wallet agent-01 --to 0x9f4E... --amount 5 --token USDC --dry-run --json
 
# 8. Execute transfer
aw send --wallet agent-01 --to 0x9f4E... --amount 5 --token USDC --json
 
# 9. Check transaction history
aw tx list --wallet agent-01 --json

7. Solana transfer

# Variables
WALLET="trading-agent"
TO="7xKXpN...9vNq"
AMOUNT="0.5"
 
# Execute
aw send --wallet $WALLET --to $TO --amount $AMOUNT --token SOL --chain solana --json
 
Expected output:
{
  "ok": true,
  "data": {
    "tx_id": "tx_sol123...",
    "tx_hash": "5Uy8...xQr",
    "status": "confirmed",
    "token": "SOL",
    "amount": "0.5",
    "to": "7xKXpN...9vNq",
    "chain": "Solana",
    "explorer_url": "https://solscan.io/tx/5Uy8...xQr"
  }
}

8. Multi-chain transfer (Ethereum)

# Variables
WALLET="trading-agent"
TO="0x9f4E..."
AMOUNT="0.01"
 
# Execute
aw send --wallet $WALLET --to $TO --amount $AMOUNT --token ETH --chain ethereum --json
 
Expected output:
{
  "ok": true,
  "data": {
    "tx_id": "tx_eth123...",
    "tx_hash": "0xabc...",
    "status": "confirmed",
    "token": "ETH",
    "amount": "0.01",
    "to": "0x9f4E...",
    "chain": "Ethereum",
    "chain_id": 1,
    "explorer_url": "https://etherscan.io/tx/0xabc..."
  }
}

9. Token swap (ETH → USDC via OKX DEX)

# Variables
WALLET="trading-agent"
FROM="ETH"
TO="USDC"
AMOUNT="0.1"
 
# Get a quote first
aw swap quote --from $FROM --to $TO --amount $AMOUNT --chain ethereum --json
 
# Execute the swap
aw swap exec --wallet $WALLET --from $FROM --to $TO --amount $AMOUNT --chain ethereum --json
 
Expected output:
{
  "ok": true,
  "data": {
    "tx_hash": "0xabc...",
    "from_token": "ETH",
    "to_token": "USDC",
    "from_amount": "0.1",
    "to_amount": "182.48",
    "dex": "OKX DEX Aggregator",
    "chain": "Ethereum",
    "status": "confirmed"
  }
}

10. Cross-chain bridge (ETH from Ethereum to Base)

# Variables
WALLET="trading-agent"
AMOUNT="0.05"
 
# Get a quote
aw bridge quote --from-chain ethereum --to-chain base --from-token ETH --to-token ETH --amount $AMOUNT --json
 
# Execute the bridge
aw bridge exec \
  --wallet $WALLET \
  --from-chain ethereum \
  --to-chain base \
  --from-token ETH \
  --to-token ETH \
  --amount $AMOUNT \
  --json
 
# Check status
aw bridge status --bridge-id bridge_abc123 --json
 
Expected output:
{
  "ok": true,
  "data": {
    "tx_hash": "0xdef...",
    "bridge_id": "bridge_abc123",
    "from_chain": "Ethereum",
    "to_chain": "Base",
    "from_amount": "0.05",
    "to_amount": "0.0498",
    "status": "pending"
  }
}

11. Open perpetual position (long BTC on Hyperliquid)

# Variables
WALLET="trading-agent"
ASSET="BTC"
SIZE="0.01"
LEVERAGE=10
 
# Check available assets
aw perp assets --json
 
# Check current prices
aw perp prices --json
 
# Open a long position
aw perp open \
  --wallet $WALLET \
  --asset $ASSET \
  --side long \
  --size $SIZE \
  --leverage $LEVERAGE \
  --json
 
# Check positions
aw perp positions --wallet $WALLET --json
 
# Close the position
aw perp close --wallet $WALLET --asset $ASSET --json
 
Expected output (open):
{
  "ok": true,
  "data": {
    "order_id": "ord_abc123",
    "asset": "BTC",
    "side": "long",
    "size": "0.01",
    "leverage": 10,
    "entry_price": "67234.50",
    "builder_fee": "0.34",
    "status": "filled"
  }
}

12. Security setup (baseline, blacklist, report)

# Initialize security baseline
aw security baseline init --json
 
# Add known malicious addresses to blacklist
aw security blacklist add --address 0xBAD...123 --reason "Known scam contract" --json
aw security blacklist add --address 0xEVIL...456 --reason "Phishing address" --json
 
# Verify baseline is intact
aw security baseline verify --json
 
# Run anomaly detection on a wallet
aw security anomaly trading-agent --json
 
# Generate comprehensive security report
aw security report --json
 
Expected output (report):
{
  "ok": true,
  "data": {
    "security_score": 95,
    "red_line_violations": 0,
    "yellow_line_warnings": 2,
    "anomalies_detected": 0,
    "baseline_status": "verified",
    "recommendations": ["Consider adding more addresses to the blacklist"]
  }
}