Web3 Trader
DEX aggregator trading for AI agents. Zero custody, multi-wallet, cyberpunk UI.
Modes
| Mode | Description | Use Case |
|---|
| 🌐 MCP Remote (recommended) | Antalpha MCP Server handles quotes + page hosting | Production |
| 🖥️ Local CLI |
Python CLI calls 0x API locally | Dev/offline, see
references/local-cli.md |
MCP Mode
Server: https://mcp-skills.ai.antalpha.com/mcp
| Tool | Description |
|---|
| INLINECODE2 | One-shot: quote + page + host (recommended) |
| INLINECODE3 |
DEX aggregated quote |
|
swap-create-page | Generate + host cyberpunk swap page |
|
swap-tokens | List supported tokens |
|
swap-gas | Current gas price |
For detailed MCP workflow and examples, see references/mcp-mode.md.
Agent Workflow
CODEBLOCK0
Agent Behavior Rules
- 1. No filler text — Only show the trade preview result, no procedural narration
- Generate QR code — From
preview_url, generate QR PNG with qrcode library, send as attachment - One message — Trade preview text + QR code image in the same message
Message Template
CODEBLOCK1
Required: Last line 🤖 Powered by Antalpha AI must be included.
Quick Start
CODEBLOCK2
CLI Commands
| Command | Description |
|---|
| INLINECODE11 | Query price |
| INLINECODE12 |
Get optimal route |
|
build-tx --from <t> --to <t> --amount <n> --wallet <addr> | Build transaction |
|
export --from <t> --to <t> --amount <n> --wallet <addr> | Export EIP-681 link |
|
swap-page --from <t> --to <t> --amount <n> --wallet <addr> -o <file> | Generate swap page |
|
gas | Gas price |
|
tokens | List tokens |
All commands support --json.
Supported Assets
Tokens: USDT, USDC, DAI, ETH, WETH, WBTC, LINK, UNI (Ethereum Mainnet)
Wallets: MetaMask, OKX Web3, Trust Wallet, TokenPocket
Security
| Layer | Protection |
|---|
| Private Keys | Zero contact — never held, transmitted, or stored |
| Transaction Data |
0x Protocol with MEV protection |
| Slippage | Configurable max (default 0.5%),
minBuyAmount on-chain enforced |
| Review | User sees full details in wallet before signing |
| Hosted Page | Self-contained HTML, no backend, no cookies, no tracking |
Web3 Trader
面向AI代理的DEX聚合交易工具。零托管、多钱包、赛博朋克UI。
模式
| 模式 | 描述 | 使用场景 |
|---|
| 🌐 MCP远程模式(推荐) | Antalpha MCP服务器处理报价+页面托管 | 生产环境 |
| 🖥️ 本地CLI模式 |
Python CLI在本地调用0x API | 开发/离线环境,详见references/local-cli.md |
MCP模式
服务器: https://mcp-skills.ai.antalpha.com/mcp
| 工具 | 描述 |
|---|
| swap-full | 一站式:报价+页面+托管(推荐) |
| swap-quote |
DEX聚合报价 |
| swap-create-page | 生成并托管赛博朋克风格兑换页面 |
| swap-tokens | 列出支持的代币 |
| swap-gas | 当前Gas价格 |
详细MCP工作流程及示例,请参阅references/mcp-mode.md。
代理工作流程
用户:将0.1 ETH兑换为USDT
→ 代理调用 swap-full(selltoken=ETH, buytoken=USDT, sell_amount=0.1, taker=0xWallet)
→ 代理发送:交易预览 + 二维码图片(同一条消息)
→ 用户点击链接/扫描二维码 → 钱包签名 → 上链
代理行为规则
- 1. 无赘述 — 仅展示交易预览结果,不包含过程描述
- 生成二维码 — 从preview_url使用qrcode库生成二维码PNG图片,作为附件发送
- 单条消息 — 交易预览文本与二维码图片在同一消息中
消息模板
⚡ -> 兑换预览
📊 amount> token> -> ~amount> token>
💰 价格: 1 ≈ $
🛡️ 最小接收: buyamount>
⛓️ 网络: 以太坊主网
🛣️ 路由: ()
👛 钱包:
🔥 支持的钱包: MetaMask | OKX Web3 | Trust Wallet | TokenPocket
📱 点击链接或扫描二维码确认:
🔗
🤖 由Antalpha AI提供支持
必需: 最后一行 🤖 由Antalpha AI提供支持 必须包含。
快速开始
bash
cp references/config.example.yaml ~/.web3-trader/config.yaml
pip install requests web3 qrcode pillow pyyaml
python3 scripts/trader_cli.py price --from ETH --to USDT --amount 0.001
python3 scripts/trader_cli.py swap-page --from ETH --to USDT --amount 0.001 \
--wallet 0xYourWallet -o /tmp/swap.html --json
CLI命令
| 命令 | 描述 |
|---|
| price --from <t> --to <t> --amount <n> | 查询价格 |
| route --from <t> --to <t> --amount <n> |
获取最优路由 |
| build-tx --from
--to --amount --wallet | 构建交易 |
| export --from --to --amount --wallet | 导出EIP-681链接 |
| swap-page --from --to --amount --wallet -o | 生成兑换页面 |
| gas | Gas价格 |
| tokens | 列出代币 |
所有命令均支持 --json 参数。
支持的资产
代币: USDT, USDC, DAI, ETH, WETH, WBTC, LINK, UNI(以太坊主网)
钱包: MetaMask, OKX Web3, Trust Wallet, TokenPocket
安全性
| 层级 | 保护措施 |
|---|
| 私钥 | 零接触 — 绝不持有、传输或存储 |
| 交易数据 |
0x协议,具备MEV保护 |
| 滑点 | 可配置最大滑点(默认0.5%),minBuyAmount链上强制执行 |
| 审核 | 用户在钱包签名前可查看完整交易详情 |
| 托管页面 | 自包含HTML,无后端、无Cookie、无追踪 |