polygon-agent-cli
Original:🇺🇸 English
Translated
Complete Polygon agent CLI. Session-based smart contract wallets (Sequence), token ops (send/swap/bridge/deposit via Trails), ERC-8004 on-chain identity + reputation, x402 micropayments. Single CLI entry point, AES-256-GCM encrypted storage.
16installs
Added on
NPX Install
npx skill4agent add 0xpolygon/polygon-agent-cli polygon-agent-cliTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Polygon Agent CLI
Prerequisites
- Node.js 20+
- Run via npx:
npx @polygonlabs/agent-cli <command> - Storage: (AES-256-GCM encrypted)
~/.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
Architecture
| Wallet | Created by | Purpose | Fund? |
|---|---|---|---|
| EOA | | Auth with Sequence Builder | NO |
| Ecosystem Wallet | | Primary spending wallet | YES |
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_KEYOptional
| Variable | Default |
|---|---|
| |
| Same as connector URL origin |
| Token-directory lookup |
| Off — logs HTTP to |
| Off — dumps fee options to stderr |
Complete Setup Flow
bash
# Phase 1: Setup (creates EOA + Sequence project, returns access key)
polygon-agent setup --name "MyAgent"
# → save privateKey (not shown again), eoaAddress, accessKey
# Phase 2: Create ecosystem wallet (auto-waits for browser approval)
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,
# UNTRUNCATED URL to the user and wait for them to open it in a browser and approve.
# Do NOT proceed to the next step until the user confirms approval (or the CLI
# automatically detects the callback). The wallet address is only available after approval.
# Phase 3: Fund wallet
polygon-agent fund
# → reads walletAddress from session, builds Trails widget URL with toAddress=<walletAddress>
# → ALWAYS run this command to get the URL — never construct it manually or hardcode any address
# → send the returned `fundingUrl` to the user; `walletAddress` in the output confirms the recipient
# Phase 4: Verify (SEQUENCE_INDEXER_ACCESS_KEY is the same as your project access key)
export SEQUENCE_INDEXER_ACCESS_KEY=$SEQUENCE_PROJECT_ACCESS_KEY
polygon-agent balances
# Phase 5: Register agent on-chain (ERC-8004, Polygon mainnet)
polygon-agent agent register --name "MyAgent" --broadcast
# → mints ERC-721 NFT, emits agentId in Registered event
# → use agentId for reputation queries and feedbackCommands Reference
Setup
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>]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]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
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
CRITICAL: Wallet Approval 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
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>.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 |
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 requests