@polygonlabs/agent-cli
v0.14.0
Published
CLI + Agent Skills for building on-chain agents on Polygon
Keywords
Readme
Polygon Agent CLI
Table of Contents
- Overview
- Quickstart
- Core Components
- Plugins & Skills
- CLI Reference
- Environment Variables
- Troubleshooting
- Development
- License
Overview
Polygon Agent CLI gives AI agents everything they need to operate onchain:
- Create and manage wallets browser-login embedded smart wallets, no private keys to manage and no keys exposed to your agent's context.
- Send tokens, swap, bridge or any action pay in any token for any onchain action. Built-in swapping, bridging, deposits, DeFi primitives, and more.
- Register agent identity and build reputation via ERC-8004
- Integrated APIs query cross-chain balances, transaction history and or query nodes via dedicated RPCs
- Payments first native gas abstraction built-in, pay end to end in stablecoins for interactions.
Quickstart
Recommended: Install on your agent
Install the Polygon Agent CLI as a skill your agent can use — works with Claude Code, Codex, Openclaw, and any agent harness that supports the skills protocol:
npx skills add https://github.com/0xPolygon/polygon-agent-cliOnce installed, your agent has access to wallet management, token operations, DEX swaps, and on-chain identity, all through the agent CLI. The long-form polygon-agent command name remains available as an alias, so both work.
Manual Install
npm (global):
npm install -g @polygonlabs/agent-cliFrom source — for contributors or local development. Use pnpm polygon-agent instead of agent for all commands.
git clone https://github.com/0xPolygon/polygon-agent-cli.git
cd polygon-agent-cli
pnpm install
pnpm polygon-agent --helpAfter install: get your agent running
Once installed via skills or npm, run the following. If running from source, run agent commands via pnpm polygon-agent from the root of the repository (e.g., pnpm polygon-agent setup --name "MyAgent").
# 1. Log in to your embedded wallet in the browser
agent wallet login
# Prints a login page URL and opens it in a browser. Choose Google or email
# on the page; once you finish, the embedded wallet is created or unlocked.
# This works whether the browser is on this machine or elsewhere, so there
# is no separate remote mode to enable. Use --local for the older loopback
# flow, which needs the browser on this same machine.
#
# No setup step needed: the CLI ships a default OMS Builder publishable key,
# and login automatically provisions your own Builder project + access key
# (saved to ~/.polygon-agent/builder.json) for indexer and Trails quota.
# 2. Fund the wallet
agent fund
# 3. Start operating
agent balances
agent send --to 0x... --amount 1.0
agent swap --from USDC --to USDT --amount 5
# 4. Register your agent on-chain
agent register --name "MyAgent" --broadcastWrite commands preview by default — omit
--broadcastto dry-run, or runagent mode autoonce to always broadcast (--dry-runstill previews any single command). SeeSKILL.mdfor the full agent-consumable reference.
Core Components
The CLI is built on three pillars to enable end to end onchain payments with your agents.
OMS: Wallet Infrastructure
OMS (Open Money Stack) powers all wallet operations, RPC access, and indexing.
| Capability | What it does | CLI command |
| ----------- | ------------------------------------------------------------------------------------------- | ------------------------------- |
| Wallets | browser-login embedded smart wallets (Account Abstraction), chain-agnostic address | wallet login, wallet list |
| RPCs | Load balanced RPCs cross-chain for onchain interactions and node queries | Used internally by all commands |
| Indexer | Token balance queries and transaction history across ERC-20/721/1155 | balances |
Wallets are created and unlocked via browser login (Google or email). The embedded wallet can call any contract and spend any amount it holds; there is no contract whitelist or per-token spend limit. The wallet address is the same across every supported chain, and sessions last about a week before you re-run wallet login.
Swap, Bridge & Deposit
Trails handles swapping, bridging, and onchain interactions enabling you to call any smart contract function and pay with any token. Trails handles it under the hood in a single transaction for your agent.
| Capability | What it does | CLI command |
| ------------ | -------------------------------------------------------------------------------------------- | ------------------------------- |
| Bridging | Move assets cross-chain into your Polygon wallet and fund the initial flows to your wallet | fund |
| Swapping | Token swaps with configurable slippage seamlessly built in | swap |
| Actions | Composable onchain operations (deposit / withdraw from yield, send tokens) | send, deposit, withdraw, send-token |
Onchain Agentic Identity
Native contracts for agent identity, reputation, and emerging payment standards.
| Capability | What it does | CLI command |
| --------------- | -------------------------------------------------------------------------------- | ------------------------------------------------------ |
| ERC-8004 | Register agents as ERC-721 NFTs with metadata and on-chain reputation | agent register, agent reputation, agent feedback |
| x402 | HTTP-native micropayment protocol for agentic payments to your favorite services | x402-pay |
| Native Apps | Direct interaction with any smart contract | call |
ERC-8004 contracts on Polygon:
- Identity Registry:
0x8004A169FB4a3325136EB29fA0ceB6D2e539a432 - Reputation Registry:
0x8004BAa17C55a88189AE136b182e5fdA19dE9b63
Plugins & Skills
The CLI ships with agent-friendly documentation designed to be consumed directly by AI agents.
| Distribution | How to install |
| ------------------------------------------- | ----------------------------------------------------------- |
| Skills (Claude Code, Codex, Openclaw, etc.) — recommended | npx skills add https://github.com/0xPolygon/polygon-agent-cli |
Once installed, the agent receives the full skill context — including wallet setup, token operations, and ERC-8004 registration, and can execute autonomously.
See SKILL.md for the full agent-consumable reference.
CLI Reference
Setup & Wallets
agent wallet login [--name <n>] [--local] [--no-fund] [--force] # Log in from the browser (choose Google or email on the login page); auto-provisions Builder credentials
agent setup --oms-publishable-key <key> # Advanced: point at your own OMS Builder project instead of the default
agent wallet logout [--name <n>] # Log out of a wallet
agent wallet list # Show all wallets
agent wallet address [--name <n>] # Show wallet address (same on every chain)
agent wallet remove [--name <n>] # Remove a stored wallet
agent fund # Open funding widget
agent mode [auto|dry-run] # Show or set the persisted transaction modeToken Operations
agent balances # Balances on session default chain
agent balances --chain arbitrum # Single chain override
agent balances --chains polygon,base,arbitrum # Same wallet, multiple chains (JSON)
agent send --to 0x... --amount 1.0 # Send POL (dry-run)
agent send --symbol USDC --to 0x... --amount 10 --broadcast
agent swap --from USDC --to USDT --amount 5 --broadcast
agent withdraw --position <aToken-or-vault> --amount max [--chain <chain>] # dry-run; add --broadcast
agent withdraw --position <aToken> --amount 0.5 --chain mainnet --broadcast # partial (underlying units)
agent call --to 0x... --data 0x... [--value <amt>] [--prefer-native-fee] [--broadcast] # arbitrary contract callwithdraw exits Aave v3 positions using your aToken address (POOL() + UNDERLYING_ASSET_ADDRESS() → Pool.withdraw), or ERC-4626 vaults (e.g. Morpho) via redeem. Dry-run prints poolAddress / vault and calldata.
The embedded wallet can call any contract on any chain, so no pre-authorization is needed — just ensure the wallet holds a little POL or USDC for gas on the target chain. To transact on a chain other than Polygon, pass --chain <name> on the command itself.
call sends a raw transaction to any contract. The relayer takes its gas fee in USDC or POL, whichever the wallet can afford; for a native-only wallet, pass --prefer-native-fee.
Agent Registry (ERC-8004)
agent register --name "MyAgent" --broadcast
agent identity --agent-id <id> # payment wallet (+ --key for metadata)
agent reputation --agent-id <id>
agent feedback --agent-id <id> --value 4.5 --broadcast
agent reviews --agent-id <id> [--include-revoked]Smart Defaults
| Default | Value | Override |
| ------------- | ---------------------- | -------------------- |
| Wallet name | main | --name <name> |
| Chain | polygon | --chain <name\|id> |
| Multi-chain balances | — | --chains <csv> (comma-separated, max 20; overrides --chain) |
| Tx mode | dry-run (preview) | --broadcast, --dry-run, or persist with agent mode auto |
Environment Variables
No environment variables are required. The CLI ships a default OMS Builder publishable key, and wallet login automatically provisions your own Builder project and access key on first login, saving it to ~/.polygon-agent/builder.json.
Advanced overrides:
| Variable | Default | Description |
| -------------------------- | ------------------------------------------- | ------------------------------------------------------------------------------- |
| OMS_PUBLISHABLE_KEY | Baked-in default | Point at your own OMS Builder project instead of the default. Can also be set via setup --oms-publishable-key <key> (persists to ~/.polygon-agent/builder.json). |
| TRAILS_API_KEY | — | Optional Trails API key for higher rate limits on swap / bridge / earn calls. |
| POLYGON_AGENT_LOGIN_UI | https://agentconnect.polygon.technology | Base URL of the browser login page opened by wallet login. |
| POLYGON_AGENT_OIDC_RELAY | https://oidc-relay.polygon.technology | Base URL of the OIDC handoff and login relay used by wallet login. |
Security
- No keys to manage. The embedded wallet is unlocked via browser login (Google or email); there are no private keys exposed to the agent's context. Credentials are stored in
~/.polygon-agent/. - Sessions expire. Wallet sessions last about a week, after which you re-run
wallet login.
Troubleshooting
| Issue | Fix |
| ------------------------------------------- | ------------------------------------------------ |
| Builder provisioning failed during login (see the stderr note) | It retries on the next wallet login; or run setup manually. Custom projects: export OMS_PUBLISHABLE_KEY |
| Not logged in | Run agent wallet login |
| Session expired | Run agent wallet login |
| Insufficient funds / can't pay gas | Run fund; for a native-only wallet pass --prefer-native-fee on call |
| Transaction failed | Omit --broadcast to dry-run first |
Development
# Install dependencies
pnpm install
# CLI (via root script)
pnpm polygon-agent --helpProject Structure
polygon-agent-cli/
├── packages/
│ └── polygon-agent-cli/ # CLI package (@polygonlabs/agent-cli)
│ ├── src/ # TypeScript source
│ │ ├── index.ts # yargs entry point
│ │ ├── commands/ # Command modules (setup, mode, wallet, operations, agent)
│ │ ├── lib/ # Shared utils (storage, mode, ethauth, tokens)
│ │ └── types.d.ts # Ambient declarations for untyped deps
│ └── contracts/ # ERC-8004 ABIs
├── skills/ # Agent skills (SKILL.md per skill; served via agentconnect)
├── pnpm-workspace.yaml
└── package.jsonRequirements: Node.js 22+
License
MIT
