> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orbitflare.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CLI

> 在 Shell 脚本、CI/CD 流水线与智能体驱动的自动化中使用 OrbitFlare CLI。每条命令支持 --json，输出机器可读。

[OrbitFlare CLI](/cn/cli) 是单一二进制，封装 RPC 查询、基于 YAML 的 gRPC 与 Jetstream 流式传输、项目脚手架与账户管理。对智能体与自动化工作流而言，关键是 `--json`：每条命令输出结构化结果，可与 `jq`、Shell 管道、GitHub Actions 与 cron 良好组合。

<Tip>
  在 Claude Code、Cursor 或其他 MCP 主机中进行交互式 AI 工作流时，优先使用 [MCP 服务器](/cn/agents/mcp)。CLI 最适合需要确定性退出码与可解析输出的 Shell 驱动自动化。
</Tip>

## 安装

```bash theme={null}
cargo install orbitflare           # requires Rust 1.85+
orbitflare --version
```

安装替代方式、认证方法与完整命令面见 [CLI 完整参考](/cn/cli)。

## 无头设置

在 CI、容器与脚本等非交互环境中，可直接用 API 密钥认证，无需浏览器流程：

```bash theme={null}
orbitflare auth login --x-orbit-key "$ORBITFLARE_API_KEY"
orbitflare config set rpc.url "$ORBITFLARE_RPC_URL"
orbitflare config set grpc.url "$ORBITFLARE_GRPC_URL"
orbitflare config set jetstream.url "$ORBITFLARE_JETSTREAM_URL"
orbitflare ping --json
```

凭证默认存储在操作系统钥匙串中。在无钥匙串的容器中，将 `ORBITFLARE_CONFIG_DIR` 设为可写路径，CLI 将回退到基于文件的配置。

## JSON 输出

每条命令支持 `--json`：

```bash theme={null}
$ orbitflare rpc slot --json
{"slot": 312456789}

$ orbitflare rpc balance Gh9ZwEm... --json
{"address": "Gh9ZwEm...", "lamports": 12500000000, "sol": 12.5}
```

与 `jq` 组合实现一行脚本：

```bash theme={null}
# Print just the slot
orbitflare rpc slot --json | jq -r '.slot'

# Alert if balance drops below 1 SOL
SOL=$(orbitflare rpc balance "$WALLET" --json | jq -r '.sol')
if (( $(echo "$SOL < 1" | bc -l) )); then
  echo "Balance low: $SOL SOL"
  exit 1
fi
```

## 使用 YAML 配置流式传输

CLI 使用声明式 YAML 配置流式传输 Jetstream 与 Yellowstone gRPC，无需编写代码：

```yaml theme={null}
# pump-trades.yaml
transactions:
  pump_trades:
    account_include:
      - "6EF8rrecthR5Dkzon8Nwu78hRvfCKubJ14M5uBEwF6P"

reconnect:
  initial_delay_ms: 100
  max_delay_ms: 30000
  multiplier: 2.0
  max_retries: 0
```

运行（Jetstream 或 Yellowstone gRPC）：

```bash theme={null}
orbitflare jet --config pump-trades.yaml | your-indexer
orbitflare grpc --config pump-trades.yaml | your-indexer
```

<Tip>
  可让具备 MCP 的智能体为你生成 YAML。[MCP 服务器](/cn/agents/mcp) 的 `subscribeTransactions` 工具可根据自然语言描述发出可直接用于 CLI 的配置。
</Tip>

## 脚本模式

### 拉取最近签名并处理

```bash theme={null}
orbitflare rpc history "$WALLET" --limit 50 --json \
  | jq -r '.[].signature' \
  | while read sig; do
      orbitflare rpc tx "$sig" --json > "txs/$sig.json"
    done
```

### CI 健康检查

```yaml theme={null}
# .github/workflows/rpc-health.yml
name: OrbitFlare RPC health
on:
  schedule:
    - cron: '*/15 * * * *'
jobs:
  ping:
    runs-on: ubuntu-latest
    steps:
      - uses: actions-rs/toolchain@v1
        with: { toolchain: stable }
      - run: cargo install orbitflare
      - run: orbitflare auth login --x-orbit-key ${{ secrets.ORBITFLARE_API_KEY }}
      - run: orbitflare config set rpc.url ${{ secrets.ORBITFLARE_RPC_URL }}
      - run: orbitflare ping --json
```

### 由智能体脚手架项目

CLI 内置常见 Solana 项目模板。智能体可列出模板并一键创建：

```bash theme={null}
orbitflare template --list --json
orbitflare template --install solana-copy-trader --dir ./bot
```

## 配置文件

在不同账户或环境间切换而无需每次重新认证：

```bash theme={null}
orbitflare auth login --profile prod --x-orbit-key "$PROD_KEY"
orbitflare auth login --profile dev  --x-orbit-key "$DEV_KEY"

orbitflare auth switch --profile prod
orbitflare auth status --json
```

## 源码

* CLI 仓库：[github.com/orbitflare/orbit-cli](https://github.com/orbitflare/orbit-cli)
* 完整参考：[CLI 文档](/cn/cli)
