UnifAI CLI
A CLI for searching and invoking services on the UnifAI network. Supports 40+ services across DeFi, token data, social media, web search, news, travel, sports, and utilities.
What it does
unifai enables you to:
- - Search services: Find services and actions using natural language queries
- Invoke services: Execute actions with customizable parameters and retry logic
- Manage configuration: Configure API keys with multiple priority levels
Available service categories
- - DeFi: Swap, lend, borrow, provide liquidity (Aave, Uniswap, Jupiter, Meteora, Pendle, Compound, 1inch, and more)
- Token & market data: Prices, OHLCV, security analysis (Birdeye, CoinGecko, DexScreener, DefiLlama, GoPlusSecurity)
- Wallet & chain data: Token balances across Solana, Ethereum, Base, BSC, Polygon
- Social media: Twitter/X search, user timelines, tweet threads
- Web search & news: General search, Google news, financial data (SerpAPI, Tavily)
- Travel: Flight and hotel search
- Sports: NBA scores, soccer results (ESPN)
- Utilities: Math, time, domain availability, Solana rent reclaimer
Installation
Install globally so the binary is available locally:
CODEBLOCK0
Or use via npx (no install needed)
CODEBLOCK1
Setup
Set your API key:
CODEBLOCK2
Or create a config file:
CODEBLOCK3
Commands
Search for tools
Always returns JSON with full payload schemas (best for agents):
CODEBLOCK4
Compact numbered list (strips schemas):
CODEBLOCK5
Invoke an action
CODEBLOCK6
With transaction signing:
CODEBLOCK7
Payload from file:
CODEBLOCK8
Sign a transaction
CODEBLOCK9
Configuration
CODEBLOCK10
Version
CODEBLOCK11
Agent Workflow
CRITICAL: Always search before invoking. Each action has its own field names (e.g. toWalletAddress for Solana, recipientWalletAddress for Polygon). Do NOT guess field names — they will fail silently or return cryptic server errors.
- 1. Search to get the action ID and exact payload schema:
CODEBLOCK12
- 2. Read the
payload field in the JSON response. It contains every field name, type, and whether it's required. Use these exact field names.
- 3. Invoke with the correct payload:
CODEBLOCK13
- 4. If
--sign is used and the response contains a txId, the transaction is automatically signed and submitted locally.
Important: Field Names Are Not Guessable
Different actions use different field names for similar concepts. Examples:
| Action | "Send to" field | "Amount" field |
|---|
| INLINECODE5 | INLINECODE6 | INLINECODE7 |
| INLINECODE8 |
recipientWalletAddress |
amount |
|
Jupiter--5--swap |
outputToken |
inAmount |
Always use unifai search first and read the payload schema. Never guess field names.
Understanding Errors
- -
Error: API key is required — Set UNIFAI_AGENT_API_KEY env var Error: ... private key is required — Set SOLANA_PRIVATE_KEY or EVM_PRIVATE_KEY for signingError: RPC URL is required — Public defaults are provided, but you can override with env vars (e.g. POLYGON_RPC_URL)- Server-side errors (e.g.
"error": "Failed to create transaction: ...") — Usually wrong field names or invalid values. Re-check the payload schema from INLINECODE23 --sign with no txId — Normal. The action didn't need signing; the response is returned as-is
Transaction Signing
Transaction signing is optional and requires private keys via environment variables:
- -
SOLANA_PRIVATE_KEY — Solana key (base58, JSON array, or path to keystore file from solana-keygen) - INLINECODE27 — EVM key (hex, with or without 0x prefix). Used for Ethereum, Polygon, Base, BSC, Hyperliquid, and Polymarket
RPC URLs (optional, public defaults are provided):
- -
SOLANA_RPC_URL — default: INLINECODE29 - INLINECODE30 — default: INLINECODE31
- INLINECODE32 — default: INLINECODE33
- INLINECODE34 — default: INLINECODE35
- INLINECODE36 — default: INLINECODE37
Public RPCs are rate-limited. Set your own RPC URLs for production use.
All signing happens locally within the CLI process. Private keys are used only by the local @solana/web3.js and ethers libraries to sign transactions before submission. The CLI source code is available at https://github.com/unifai-network/unifai-sdk-js/tree/main/src/cli.
Common Examples
CODEBLOCK14
Security Notes
- - Private keys:
SOLANA_PRIVATE_KEY and EVM_PRIVATE_KEY are only needed for transaction signing. - Local signing: All transaction signing happens locally in-process using
@solana/web3.js and ethers. Private keys are never sent to external API.
UnifAI CLI
用于在UnifAI网络上搜索和调用服务的命令行工具。支持DeFi、代币数据、社交媒体、网页搜索、新闻、旅行、体育和实用工具等40多项服务。
功能概述
unifai 使您能够:
- - 搜索服务:使用自然语言查询查找服务和操作
- 调用服务:使用可自定义参数和重试逻辑执行操作
- 管理配置:配置具有多个优先级级别的API密钥
可用服务类别
- - DeFi:兑换、借贷、提供流动性(Aave、Uniswap、Jupiter、Meteora、Pendle、Compound、1inch等)
- 代币与市场数据:价格、OHLCV、安全分析(Birdeye、CoinGecko、DexScreener、DefiLlama、GoPlusSecurity)
- 钱包与链数据:Solana、Ethereum、Base、BSC、Polygon上的代币余额
- 社交媒体:Twitter/X搜索、用户时间线、推文线程
- 网页搜索与新闻:通用搜索、Google新闻、金融数据(SerpAPI、Tavily)
- 旅行:航班和酒店搜索
- 体育:NBA比分、足球赛果(ESPN)
- 实用工具:数学、时间、域名可用性、Solana租金回收
安装
全局安装以便本地使用二进制文件:
bash
npm install -g unifai-sdk
或通过npx使用(无需安装)
bash
npx -p unifai-sdk unifai
设置
设置您的API密钥:
bash
export UNIFAIAGENTAPI_KEY=your-key-here
或创建配置文件:
bash
unifai config init
编辑 ~/.config/unifai-cli/config.yaml
命令
搜索工具
始终返回包含完整负载模式的JSON(最适合代理):
bash
unifai search --query solana swap
unifai search --query token price --limit 5
紧凑编号列表(去除模式):
bash
unifai search --query solana --no-schema
调用操作
bash
unifai invoke --action Solana--7--getBalance --payload {address:...}
带交易签名:
bash
unifai invoke --action Solana--7--transfer --payload {toWalletAddress:...,amount:0.01} --sign
从文件加载负载:
bash
unifai invoke --action MyAction --payload @payload.json
签名交易
bash
unifai tx sign
unifai tx sign --json
配置
bash
unifai config init # 创建配置文件
unifai config show # 显示当前配置和来源
unifai config show --json # JSON输出
版本
bash
unifai version
unifai --version
代理工作流程
关键:调用前务必先搜索。 每个操作都有其自己的字段名称(例如Solana的toWalletAddress,Polygon的recipientWalletAddress)。不要猜测字段名称——它们会静默失败或返回难以理解的服务器错误。
- 1. 搜索以获取操作ID和精确的负载模式:
bash
unifai search --query swap SOL to USDC
- 2. 读取JSON响应中的payload字段。它包含每个字段名称、类型以及是否为必填项。使用这些确切的字段名称。
- 3. 使用正确的负载调用:
bash
unifai invoke --action Jupiter--5--swap --payload {inputToken:SOL,outputToken:USDC,inAmount:0.1} --sign
- 4. 如果使用了--sign且响应包含txId,交易将自动在本地签名并提交。
重要提示:字段名称不可猜测
不同的操作为相似的概念使用不同的字段名称。示例:
| 操作 | 发送到字段 | 金额字段 |
|---|
| Solana--7--transfer | toWalletAddress | amount |
| Polygon--160--transfer |
recipientWalletAddress | amount |
| Jupiter--5--swap | outputToken | inAmount |
始终先使用unifai search 并读取负载模式。切勿猜测字段名称。
理解错误
- - Error: API key is required — 设置UNIFAIAGENTAPIKEY环境变量
- Error: ... private key is required — 设置SOLANAPRIVATEKEY或EVMPRIVATEKEY用于签名
- Error: RPC URL is required — 提供公共默认值,但您可以使用环境变量覆盖(例如POLYGONRPC_URL)
- 服务器端错误(例如error: Failed to create transaction: ...)— 通常是错误的字段名称或无效值。重新检查unifai search中的负载模式
- --sign但没有txId — 正常情况。该操作不需要签名;响应按原样返回
交易签名
交易签名是可选的,需要通过环境变量提供私钥:
- - SOLANAPRIVATEKEY — Solana密钥(base58、JSON数组或来自solana-keygen的密钥库文件路径)
- EVMPRIVATEKEY — EVM密钥(十六进制,带或不带0x前缀)。用于Ethereum、Polygon、Base、BSC、Hyperliquid和Polymarket
RPC URL(可选,提供公共默认值):
- - SOLANARPCURL — 默认值:https://api.mainnet-beta.solana.com
- ETHEREUMRPCURL — 默认值:https://eth.llamarpc.com
- BASERPCURL — 默认值:https://mainnet.base.org
- BSCRPCURL — 默认值:https://bsc-dataseed.binance.org
- POLYGONRPCURL — 默认值:https://rpc-mainnet.matic.quiknode.pro
公共RPC有速率限制。生产环境请设置您自己的RPC URL。
所有签名都在CLI进程内本地完成。私钥仅由本地的@solana/web3.js和ethers库在提交前用于签名交易。CLI源代码可在https://github.com/unifai-network/unifai-sdk-js/tree/main/src/cli获取。
常见示例
bash
步骤1:始终先搜索以获取精确模式
unifai search --query solana transfer
Solana转账(使用toWalletAddress,而非to)
unifai invoke --action Solana--7--transfer \
--payload {toWalletAddress:...,amount:0.01} --sign
Solana上的Jupiter兑换
unifai invoke --action Jupiter--5--swap \
--payload {inputToken:SOL,outputToken:USDC,inAmount:0.1} --sign
Polygon转账(使用recipientWalletAddress)
unifai invoke --action Polygon--160--transfer \
--payload {recipientWalletAddress:0x...,amount:0.01} --sign
Polymarket - 获取未成交订单(只读,但仍需签名)
unifai invoke --action polymarket--127--getOpenOrders --payload {} --sign
只读操作不需要--sign
unifai invoke --action Birdeye--174--RetrieveTheLatestPrice \
--payload {address:So11111111111111111111111111111111111111112,chain:solana}
搜索任何功能
unifai search --query weather forecast
unifai search --query sports scores
安全说明
- - 私钥:SOLANAPRIVATEKEY和EVMPRIVATEKEY仅在交易签名时需要。
- 本地签名:所有交易签名都在进程内本地使用@solana/web3.js和ethers完成。私钥永远不会发送到外部API。