polygon-agent-cli
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePolygon Agent CLI
Polygon Agent CLI
Prerequisites
前置要求
- Node.js 20+
- Run via npx:
npx @polygonlabs/agent-cli <command> - Storage: (AES-256-GCM encrypted)
~/.polygon-agent/
- Node.js 20+
- 通过npx运行:
npx @polygonlabs/agent-cli <command> - 存储路径:(AES-256-GCM加密)
~/.polygon-agent/
Session Initialization
会话初始化
Before running any commands, use the Read tool to check :
~/.polygon-agent/builder.json- If it exists — extract from the JSON and export as plain shell vars (no
accessKeysubshells):$()bashexport SEQUENCE_PROJECT_ACCESS_KEY=<accessKey> export SEQUENCE_INDEXER_ACCESS_KEY=$SEQUENCE_PROJECT_ACCESS_KEY export TRAILS_API_KEY=$SEQUENCE_PROJECT_ACCESS_KEY - If it doesn't exist — the user hasn't completed setup yet. Proceed to Phase 1 () which will create the file.
setup
运行任何命令前,使用读取工具检查:
~/.polygon-agent/builder.json- 如果文件存在 — 从JSON中提取,导出为普通shell变量(不要使用
accessKey子shell):$()bashexport SEQUENCE_PROJECT_ACCESS_KEY=<accessKey> export SEQUENCE_INDEXER_ACCESS_KEY=$SEQUENCE_PROJECT_ACCESS_KEY export TRAILS_API_KEY=$SEQUENCE_PROJECT_ACCESS_KEY - 如果文件不存在 — 用户尚未完成设置,请进入阶段1()创建该文件。
setup
Architecture
架构
| Wallet | Created by | Purpose | Fund? |
|---|---|---|---|
| EOA | | Auth with Sequence Builder | NO |
| Ecosystem Wallet | | Primary spending wallet | YES |
| 钱包 | 创建方式 | 用途 | 需要充值? |
|---|---|---|---|
| EOA | | Sequence Builder身份验证 | 否 |
| Ecosystem Wallet | | 主要消费钱包 | 是 |
Environment Variables
环境变量
Required
必填
| Variable | When |
|---|---|
| Wallet creation, swaps, balance checks, Trails |
One key, three names — and are the same value as . Set them all once:
SEQUENCE_INDEXER_ACCESS_KEYTRAILS_API_KEYSEQUENCE_PROJECT_ACCESS_KEYbash
export SEQUENCE_PROJECT_ACCESS_KEY=<access-key-from-setup>
export SEQUENCE_INDEXER_ACCESS_KEY=$SEQUENCE_PROJECT_ACCESS_KEY
export TRAILS_API_KEY=$SEQUENCE_PROJECT_ACCESS_KEY| 变量名 | 适用场景 |
|---|---|
| 钱包创建、兑换、余额查询、Trails操作 |
一个密钥,三处使用 — 和的值与完全相同,只需统一设置一次:
SEQUENCE_INDEXER_ACCESS_KEYTRAILS_API_KEYSEQUENCE_PROJECT_ACCESS_KEYbash
export SEQUENCE_PROJECT_ACCESS_KEY=<access-key-from-setup>
export SEQUENCE_INDEXER_ACCESS_KEY=$SEQUENCE_PROJECT_ACCESS_KEY
export TRAILS_API_KEY=$SEQUENCE_PROJECT_ACCESS_KEYOptional
选填
| Variable | Default |
|---|---|
| |
| Same as connector URL origin |
| Token-directory lookup |
| Off — logs HTTP to |
| Off — dumps fee options to stderr |
| 变量名 | 默认值 |
|---|---|
| |
| 与连接器URL的源站相同 |
| 代币目录查询表 |
| 关闭 — 开启后会将HTTP日志写入 |
| 关闭 — 开启后会将手续费选项输出到stderr |
Complete Setup Flow
完整设置流程
bash
undefinedbash
undefinedPhase 1: Setup (creates EOA + Sequence project, returns access key)
阶段1:设置(创建EOA + Sequence项目,返回访问密钥)
polygon-agent setup --name "MyAgent"
polygon-agent setup --name "MyAgent"
→ save privateKey (not shown again), eoaAddress, accessKey
→ 保存privateKey(不会再次展示)、eoaAddress、accessKey
Phase 2: Create ecosystem wallet (auto-waits for browser approval)
阶段2:创建生态钱包(自动等待浏览器授权)
export SEQUENCE_PROJECT_ACCESS_KEY=<accessKey>
polygon-agent wallet create --usdc-limit 100 --native-limit 5
export SEQUENCE_PROJECT_ACCESS_KEY=<accessKey>
polygon-agent wallet create --usdc-limit 100 --native-limit 5
→ IMPORTANT: The command outputs an approvalUrl
. You MUST send the COMPLETE,
approvalUrl→ 重要提示:命令会输出一个approvalUrl
。你必须将完整、未截断的URL发送给用户,等待用户在浏览器中打开并完成授权。
approvalUrlUNTRUNCATED URL to the user and wait for them to open it in a browser and approve.
在用户确认授权(或CLI自动检测到回调)前,不要进入下一步。钱包地址仅在授权完成后才会生成。
Do NOT proceed to the next step until the user confirms approval (or the CLI
阶段3:钱包充值
automatically detects the callback). The wallet address is only available after approval.
—
Phase 3: Fund wallet
—
polygon-agent fund
polygon-agent fund
→ reads walletAddress from session, builds Trails widget URL with toAddress=<walletAddress>
→ 从会话中读取walletAddress,构建Trails部件URL,toAddress参数自动设为<walletAddress>
→ ALWAYS run this command to get the URL — never construct it manually or hardcode any address
→ 必须运行此命令获取URL,不要手动构造或硬编码任何地址
→ send the returned fundingUrl
to the user; walletAddress
in the output confirms the recipient
fundingUrlwalletAddress→ 将返回的fundingUrl
发送给用户,输出中的walletAddress
可确认收款方信息
fundingUrlwalletAddressPhase 4: Verify (SEQUENCE_INDEXER_ACCESS_KEY is the same as your project access key)
阶段4:验证(SEQUENCE_INDEXER_ACCESS_KEY与你的项目访问密钥相同)
export SEQUENCE_INDEXER_ACCESS_KEY=$SEQUENCE_PROJECT_ACCESS_KEY
polygon-agent balances
export SEQUENCE_INDEXER_ACCESS_KEY=$SEQUENCE_PROJECT_ACCESS_KEY
polygon-agent balances
Phase 5: Register agent on-chain (ERC-8004, Polygon mainnet)
阶段5:在链上注册Agent(ERC-8004,Polygon主网)
polygon-agent agent register --name "MyAgent" --broadcast
polygon-agent agent register --name "MyAgent" --broadcast
→ mints ERC-721 NFT, emits agentId in Registered event
→ mint ERC-721 NFT,在Registered事件中返回agentId
→ use agentId for reputation queries and feedback
→ 可使用agentId查询声誉和反馈
undefinedundefinedCommands Reference
命令参考
Setup
设置
bash
polygon-agent setup --name <name> [--force]bash
polygon-agent setup --name <name> [--force]Wallet
钱包
bash
polygon-agent wallet create [--name <n>] [--chain polygon] [--timeout <sec>] [--no-wait]
[--native-limit <amt>] [--usdc-limit <amt>] [--usdt-limit <amt>]
[--token-limit <SYM:amt>] # repeatable
[--usdc-to <addr> --usdc-amount <amt>] # one-off scoped transfer
[--contract <addr>] # whitelist contract (repeatable)
polygon-agent wallet import --ciphertext '<blob>|@<file>' [--name <n>] [--rid <rid>]
polygon-agent wallet list
polygon-agent wallet address [--name <n>]
polygon-agent wallet remove [--name <n>]bash
polygon-agent wallet create [--name <n>] [--chain polygon] [--timeout <sec>] [--no-wait]
[--native-limit <amt>] [--usdc-limit <amt>] [--usdt-limit <amt>]
[--token-limit <SYM:amt>] # 可重复
[--usdc-to <addr> --usdc-amount <amt>] # 一次性限定范围转账
[--contract <addr>] # 合约白名单(可重复)
polygon-agent wallet import --ciphertext '<blob>|@<file>' [--name <n>] [--rid <rid>]
polygon-agent wallet list
polygon-agent wallet address [--name <n>]
polygon-agent wallet remove [--name <n>]Operations
操作
bash
polygon-agent balances [--wallet <n>] [--chain <chain>]
polygon-agent send --to <addr> --amount <num> [--symbol <SYM>] [--broadcast]
polygon-agent send-native --to <addr> --amount <num> [--broadcast] [--direct]
polygon-agent send-token --symbol <SYM> --to <addr> --amount <num> [--broadcast]
polygon-agent swap --from <SYM> --to <SYM> --amount <num> [--to-chain <chain>] [--slippage <num>] [--broadcast]
polygon-agent deposit --asset <SYM> --amount <num> [--protocol aave|morpho] [--broadcast]
polygon-agent fund [--wallet <n>] [--token <addr>]
polygon-agent x402-pay --url <url> --wallet <n> [--method GET] [--body <str>] [--header Key:Value]bash
polygon-agent balances [--wallet <n>] [--chain <chain>]
polygon-agent send --to <addr> --amount <num> [--symbol <SYM>] [--broadcast]
polygon-agent send-native --to <addr> --amount <num> [--broadcast] [--direct]
polygon-agent send-token --symbol <SYM> --to <addr> --amount <num> [--broadcast]
polygon-agent swap --from <SYM> --to <SYM> --amount <num> [--to-chain <chain>] [--slippage <num>] [--broadcast]
polygon-agent deposit --asset <SYM> --amount <num> [--protocol aave|morpho] [--broadcast]
polygon-agent fund [--wallet <n>] [--token <addr>]
polygon-agent x402-pay --url <url> --wallet <n> [--method GET] [--body <str>] [--header Key:Value]Agent (ERC-8004)
Agent (ERC-8004)
bash
polygon-agent agent register --name <n> [--agent-uri <uri>] [--metadata <k=v,k=v>] [--broadcast]
polygon-agent agent wallet --agent-id <id>
polygon-agent agent metadata --agent-id <id> --key <key>
polygon-agent agent reputation --agent-id <id> [--tag1 <tag>]
polygon-agent agent reviews --agent-id <id>
polygon-agent agent feedback --agent-id <id> --value <score> [--tag1 <t>] [--tag2 <t>] [--endpoint <e>] [--broadcast]ERC-8004 contracts (Polygon mainnet):
- IdentityRegistry:
0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 - ReputationRegistry:
0x8004BAa17C55a88189AE136b182e5fdA19dE9b63
bash
polygon-agent agent register --name <n> [--agent-uri <uri>] [--metadata <k=v,k=v>] [--broadcast]
polygon-agent agent wallet --agent-id <id>
polygon-agent agent metadata --agent-id <id> --key <key>
polygon-agent agent reputation --agent-id <id> [--tag1 <tag>]
polygon-agent agent reviews --agent-id <id>
polygon-agent agent feedback --agent-id <id> --value <score> [--tag1 <t>] [--tag2 <t>] [--endpoint <e>] [--broadcast]ERC-8004合约(Polygon主网):
- IdentityRegistry:
0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 - ReputationRegistry:
0x8004BAa17C55a88189AE136b182e5fdA19dE9b63
Key Behaviors
核心特性
- Dry-run by default — all write commands require to execute
--broadcast - Smart defaults — ,
--wallet main, auto-wait on--chain polygonwallet create - Fee preference — auto-selects USDC over native POL when both available
- — reads
fundfrom the wallet session and sets it aswalletAddressin the Trails widget URL. Always runtoAddressto get the correct URL — never construct it manually or hardcode any address. The returned JSON containspolygon-agent fundandfundingUrlso you can confirm the pre-filled recipient before sharing.walletAddress - — picks highest-TVL pool via Trails
deposit. Important:getEarnPoolsrestricts the USDC session to--usdc-limitcalls only, which blocks thetransfercall that deposit requires. To useapprove, omitdepositand instead whitelist USDC via--usdc-limit(unrestricted). Also add the protocol pool address via--contract 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359.--contract <depositAddress> - — probes endpoint for 402, smart wallet funds builder EOA with exact token amount, EOA signs EIP-3009 payment. Chain auto-detected from 402 response
x402-pay - — bypasses ValueForwarder contract for direct EOA transfer
send-native --direct - Session permissions — without etc., session gets bare-bones defaults and may not transact
--usdc-limit
- 默认试运行 — 所有写入操作都需要添加才会实际执行
--broadcast - 智能默认值 — 默认、
--wallet main,--chain polygon命令默认等待授权wallet create - 手续费偏好 — 当USDC和原生POL都可用时,自动选择USDC支付手续费
- 命令 — 从钱包会话读取
fund,自动设置为Trails部件URL的walletAddress参数。必须运行toAddress获取正确的URL,不要手动构造或硬编码任何地址。返回的JSON包含polygon-agent fund和fundingUrl,你可以在分享前确认预填的收款方信息。walletAddress - 命令 — 通过Trails的
deposit接口选择TVL最高的池子。重要提示:getEarnPools会将USDC会话限制为仅允许--usdc-limit调用,会阻止deposit所需的transfer调用。要使用approve功能,请不要设置deposit,改为通过--usdc-limit(无限制)将USDC加入白名单,同时通过--contract 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359添加协议池子地址。--contract <depositAddress> - 命令 — 探测端点是否返回402,智能钱包将精确金额的代币转入builder EOA,EOA签署EIP-3009支付。链信息会从402响应中自动识别
x402-pay - — 绕过ValueForwarder合约,直接通过EOA转账
send-native --direct - 会话权限 — 如果没有设置等参数,会话仅具备基础默认权限,可能无法执行交易
--usdc-limit
CRITICAL: Wallet Approval URL
重要提示:钱包批准URL
When outputs a URL in the or field, you MUST send the COMPLETE, UNTRUNCATED URL to the user. The URL contains cryptographic parameters (public key, callback token) that are required for session approval. If any part is cut off, the approval will fail.
wallet createurlapprovalUrl- Do NOT shorten, summarize, or add to the URL
... - Do NOT split the URL across multiple messages
- Output the raw URL exactly as returned by the CLI
当命令在或字段输出URL时,你必须将完整、未截断的URL发送给用户。URL包含会话授权所需的加密参数(公钥、回调令牌),任何部分被截断都会导致授权失败。
wallet createurlapprovalUrl- 不要缩短、摘要URL,也不要在URL中添加
... - 不要将URL拆分到多条消息中
- 完全按照CLI返回的原始内容输出URL
Callback Modes
回调模式
The command automatically starts a local HTTP server and opens a Cloudflare Quick Tunnel () — no account or token required. The binary is auto-downloaded to on first use if not already installed. The connector UI POSTs the encrypted session back through the tunnel regardless of where the agent is running. The tunnel and server are torn down automatically once the session is received.
wallet create*.trycloudflare.comcloudflared~/.polygon-agent/bin/cloudflaredTiming: The is only valid while the CLI process is running. Open it immediately and complete wallet approval within the timeout window (default 300s). Never reuse a URL from a previous run — the tunnel is torn down when the CLI exits.
approvalUrlManual fallback (if cloudflared is unavailable): The CLI omits so the connector UI displays the encrypted blob in the browser. The CLI then prompts:
callbackUrltext
After approving in the browser, the encrypted blob will be shown.
Paste it below and press Enter:
> <paste blob here>The blob is also saved to for reference. To import later:
/tmp/polygon-session-<rid>.txtbash
polygon-agent wallet import --ciphertext @/tmp/polygon-session-<rid>.txtwallet create*.trycloudflare.comcloudflared~/.polygon-agent/bin/cloudflared时效说明:仅在CLI进程运行期间有效,请立即打开并在超时窗口(默认300秒)内完成钱包授权。不要重复使用之前运行生成的URL — CLI退出时隧道就会被销毁。
approvalUrl手动降级方案(如果cloudflared不可用):CLI会省略,连接器UI会在浏览器中展示加密blob。随后CLI会提示:
callbackUrltext
在浏览器中完成授权后,会展示加密blob。
请将其粘贴到下方后按回车:
> <paste blob here>Blob也会保存到供后续参考。如需后续导入,运行:
/tmp/polygon-session-<rid>.txtbash
polygon-agent wallet import --ciphertext @/tmp/polygon-session-<rid>.txtTroubleshooting
故障排查
| Issue | Fix |
|---|---|
| Add |
| Run |
| |
| Re-run |
| Set |
| Add |
| cloudflared unavailable — paste blob from browser when prompted; blob saved to |
| CLI timed out and tunnel is gone — re-run |
| Copy the ciphertext shown below that message; run |
| Deposit session rejected | |
| Wrong recipient in Trails widget | Run |
| 问题 | 解决方案 |
|---|---|
| 添加 |
| 先运行 |
| 运行 |
| 重新执行 |
| 设置 |
| 添加 |
| cloudflared不可用 — 按照提示粘贴浏览器返回的blob;blob已保存到 |
访问 | CLI已超时,隧道已销毁 — 重新执行 |
浏览器中提示 | 复制提示下方展示的密文;运行 |
| 存入会话被拒绝 | |
| Trails部件中的收款方错误 | 运行 |
File Structure
文件结构
text
~/.polygon-agent/
├── .encryption-key # AES-256-GCM key (auto-generated, 0600)
├── builder.json # EOA privateKey (encrypted), eoaAddress, accessKey, projectId
├── wallets/<name>.json # walletAddress, session, chainId, chain
└── requests/<rid>.json # Pending wallet creation requeststext
~/.polygon-agent/
├── .encryption-key # AES-256-GCM密钥(自动生成,权限0600)
├── builder.json # EOA privateKey(加密)、eoaAddress、accessKey、projectId
├── wallets/<name>.json # walletAddress、session、chainId、chain
└── requests/<rid>.json # 待处理的钱包创建请求