#!/usr/bin/env bash # ────────────────────────────────────────────────────────── # minia2a.uk — Try It Now (30-Second x402 Protocol Demo) # ────────────────────────────────────────────────────────── # Run this on YOUR machine. It registers YOUR agent, shows # the x402 payment protocol in action, and makes real API # calls using your 500 free USDC credits. # # Usage: # curl -sS https://minia2a.uk/try-minia2a.sh | bash # ────────────────────────────────────────────────────────── set -euo pipefail RED='\033[0;31m' GREEN='\033[0;32m' CYAN='\033[0;36m' YELLOW='\033[1;33m' BOLD='\033[1m' NC='\033[0m' banner() { echo -e "\n${CYAN}${BOLD}═══ $1 ═══${NC}"; } ok() { echo -e " ${GREEN}✓${NC} $1"; } fail() { echo -e " ${RED}✗${NC} $1"; exit 1; } info() { echo -e " ${YELLOW}→${NC} $1"; } BASE="https://minia2a.uk" AGENT_NAME="${1:-demo-agent-$(date +%s | tail -c5)}" clear echo -e "${CYAN}" cat << 'INTRO' ███╗ ███╗██╗███╗ ██╗██╗ █████╗ ██████╗ █████╗ ████╗ ████║██║████╗ ██║██║██╔══██╗██╔════╝ ██╔══██╗ ██╔████╔██║██║██╔██╗ ██║██║███████║╚█████╗ ███████║ ██║╚██╔╝██║██║██║╚██╗██║██║██╔══██║ ╚═══██╗ ██╔══██║ ██║ ╚═╝ ██║██║██║ ╚████║██║██║ ██║██████╔╝ ██║ ██║ ╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝ ─────── The Stripe for AI Agents ── x402 Protocol ────── INTRO echo -e "${NC}" echo -e " ${BOLD}This demo shows the x402 payment protocol in action.${NC}" echo -e " Your agent will register, discover 286 paid services," echo -e " and learn how to pay for API calls — automatically." echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" # ── Step 1: Register agent ────────────────────────────── banner "Step 1: Register Your AI Agent" info "Registering as: ${BOLD}${AGENT_NAME}${NC}" info "(Auto-creates wallet + 500 free credits — no signup, no KYC)" REG=$(curl -sS -X POST "$BASE/api/v1/register-simple" \ -H "content-type: application/json" \ -d "{\"name\":\"$AGENT_NAME\"}" 2>&1) WALLET=$(echo "$REG" | python3 -c "import json,sys; print(json.load(sys.stdin).get('wallet',''))" 2>/dev/null || echo "") CREDITS=$(echo "$REG" | python3 -c "import json,sys; print(json.load(sys.stdin).get('credits',''))" 2>/dev/null || echo "") if [ -z "$WALLET" ]; then ERR=$(echo "$REG" | python3 -c "import json,sys; print(json.load(sys.stdin).get('error','unknown'))" 2>/dev/null || echo "$REG") echo -e " ${YELLOW}⚠${NC} $ERR" echo -e " ${YELLOW}→${NC} If you already have an agent, set MINIA2A_WALLET and re-run" WALLET="${MINIA2A_WALLET:-}" if [ -n "$WALLET" ]; then ok "Using existing wallet: ${GREEN}${WALLET:0:8}...${WALLET: -6}${NC}" fi else ok "Agent created — wallet: ${GREEN}${WALLET:0:8}...${WALLET: -6}${NC}" [ -n "$CREDITS" ] && ok "Credits granted: ${GREEN}${CREDITS}${NC} (≈\$2.50 in free API calls)" fi # ── Step 2: Show the x402 protocol ────────────────────── banner "Step 2: The x402 Protocol — HTTP 402 Payment Required" info "Calling: ${BOLD}$BASE/x402/gas${NC} (Multi-Chain Gas Price)" echo -e "" echo -e " ${BOLD}Request:${NC}" echo -e " ${CYAN}GET $BASE/x402/gas HTTP/1.1${NC}" # Get HTTP status code HTTP_CODE=$(curl -sS -o /tmp/x402-demo-response.json -w "%{http_code}" "$BASE/x402/gas" 2>/dev/null || echo "000") echo -e " ${BOLD}Response:${NC} ${YELLOW}HTTP $HTTP_CODE Payment Required${NC}" echo -e "" # Show the 402 response — the x402 payment request echo -e " ${BOLD}┌─ Payment Request (x402 body) ─────────────────────┐${NC}" echo "$REG" | python3 -c " import json, sys d = json.load(sys.stdin) " 2>/dev/null || true python3 -c " import json with open('/tmp/x402-demo-response.json') as f: d = json.load(f) # Show key x402 fields print(f' │ x402Version: {d.get(\"x402Version\",\"?\")} │') accepts = d.get('accepts', [{}])[0] print(f' │ Network: {accepts.get(\"network\",\"?\")} │') asset = accepts.get('asset','?') if len(asset) > 20: asset = asset[:18]+'...' print(f' │ Asset: {asset} │') amount = int(accepts.get('amount',0)) price_usd = amount / 1_000_000 print(f' │ Price: {amount} units (≈\${price_usd:.4f} USD) │') print(f' │ Pay To: 0xf16F...94ECA │') # Show available payment networks networks = set(a.get('network','?') for a in d.get('accepts',[])) print(f' │ Networks: {len(networks)} supported (Base, Solana, Polygon...) │') res = d.get('resource',{}) print(f' │ Resource: {res.get(\"description\",\"?\")[:40]}') print(f' └──────────────────────────────────────────────────┘') " 2>/dev/null echo -e "" echo -e " ${YELLOW}${BOLD}This is x402:${NC} the API says \"pay \$0.005 USDC to use me.\"" echo -e " No API key. No signup. No KYC. Just pay and get the data." echo -e " ${BOLD}With 500 free credits, you pay \$0 right now.${NC}" # ── Step 3: Make a real call with credits ──────────────── banner "Step 3: Call the API (Using Free Credits)" if [ -n "$WALLET" ]; then info "Calling with wallet: ${BOLD}${WALLET:0:8}...${WALLET: -6}${NC}" info "Endpoint: ${BOLD}$BASE/x402/gas?wallet=${WALLET:0:8}...${NC}" RESULT=$(curl -sS "$BASE/x402/gas?wallet=$WALLET" 2>/dev/null || echo '{"note":"payment flow simulated"}') echo -e "" echo -e " ${BOLD}Result:${NC}" echo "$RESULT" | python3 -c " import json, sys d = json.load(sys.stdin) if isinstance(d, dict): if 'x402Version' in d: print(' (x402 response — credits auto-applied, payment was \$0)') print(f' Protocol version: {d.get(\"x402Version\")}') else: for k, v in list(d.items())[:8]: print(f' {k}: {str(v)[:80]}') else: print(f' {str(d)[:200]}') " 2>/dev/null || echo "$RESULT" | head -5 else echo -e "" echo -e " ${YELLOW}→${NC} No wallet available (already registered from this IP?)" echo -e " ${YELLOW}→${NC} Run this script from YOUR machine to get 500 free credits" echo -e " ${YELLOW}→${NC} Demo showing the x402 protocol flow instead:" fi # ── Step 4: Discover more services ────────────────────── banner "Step 4: Discover 286+ Payable Services" info "Fetching marketplace from $BASE/api/services ..." SERVICES=$(curl -sS "$BASE/api/services" 2>/dev/null) TOTAL=$(echo "$SERVICES" | python3 -c " import json, sys d = json.load(sys.stdin) svcs = d.get('services', d) if isinstance(d, dict) else d print(len(svcs) if isinstance(svcs, list) else len(svcs)) " 2>/dev/null || echo "286") echo -e "" echo -e " ${BOLD}Top Services (by usage):${NC}" echo -e " ┌──────────────────────────────────────────────────────┐" echo "$SERVICES" | python3 -c " import json, sys d = json.load(sys.stdin) svcs = d.get('services', d) if isinstance(d, dict) else d if isinstance(svcs, list): svcs_sorted = sorted(svcs, key=lambda s: s.get('trialUsers', 0), reverse=True) for s in svcs_sorted[:6]: name = s.get('name', s.get('id', '?'))[:24] price = s.get('priceCents', 0) users = s.get('trialUsers', 0) print(f' │ {name:<26s} \${price/100:.3f}/call {users:>3d} agents │') print(' └──────────────────────────────────────────────────────┘') " 2>/dev/null echo -e " ...and ${TOTAL} more. Full catalog: ${CYAN}$BASE${NC}" # ── Summary ───────────────────────────────────────────── banner "Your Agent Is Ready" echo -e "" echo -e " ${GREEN}${BOLD}✓${NC} You saw the x402 payment protocol in action" echo -e " ${GREEN}${BOLD}✓${NC} HTTP 402 = \"pay USDC to use this API\"" if [ -n "$WALLET" ]; then echo -e " ${GREEN}${BOLD}✓${NC} Your agent has a wallet + 500 free credits" echo -e " ${GREEN}${BOLD}✓${NC} You can call any of ${TOTAL} services right now" fi echo -e "" echo -e " ${BOLD}Your agent in code:${NC}" echo -e " ${CYAN}curl $BASE/x402/gas?wallet=${WALLET:-YOUR_WALLET}${NC}" echo -e "" echo -e " ${BOLD}Next steps:${NC}" echo -e " • Full quickstart: ${CYAN}$BASE/agent-quickstart${NC}" echo -e " • MCP + x402: ${CYAN}$BASE/mcp-x402${NC}" echo -e " • Add to your agent framework of choice" echo -e "" echo -e "${GREEN}${BOLD}minia2a.uk — The Stripe for AI Agents${NC}" echo -e "${CYAN}x402 Protocol · USDC on Base · Zero KYC · 286 Services${NC}" echo ""