---
title: Nile Markets CLI
description: Command-line interface for the Nile Markets onchain FX forward protocol — zero-config for Sepolia, supports EUR/USD + USD/JPY
version: 0.3.3
---

# Nile Markets CLI

Command-line interface for reading protocol state and executing trades on the Nile Markets onchain FX forward protocol (EUR/USD + USD/JPY). Pass `--pair USD/JPY` on `position`, `oracle`, and `simulate` subcommands to target a non-default pair.

> **Zero-config for Sepolia** — The installed binary embeds Sepolia contract addresses, a free public RPC endpoint, and the subgraph URL. No environment variables, config files, or API keys needed for reads. For writes, just set up a wallet.

---

## Install

```bash
npm install -g @nile-markets/cli
```

One-shot without installing (`-y` skips the prompt; `@latest` bypasses a stale npx cache):

```bash
npx -y @nile-markets/cli@latest pool state
```

Or via the installer script:

```bash
curl -fsSL https://mcp.nilemarkets.com/install.sh | bash
```

Or via Cargo:

```bash
cargo install nile-markets-cli
```

All methods install the same prebuilt `nile` binary (macOS/Linux, x64 + arm64); Cargo builds from source.

Verify installation:

```bash
nile --version
```

---

## Wallet Setup (writes only)

Read commands work immediately after install. Write commands (open/close positions, deposit/withdraw) require an [OWS-compatible wallet](https://docs.openwallet.sh/) for transaction signing.

**1. Install OWS:**

```bash
curl -fsSL https://openwallet.sh/install.sh | bash
```

**2. Import your private key:**

```bash
echo "<your-private-key>" | ows wallet import --name my-wallet --private-key --chain evm
```

**3. Configure the CLI to use your wallet:**

```bash
nile config set-wallet my-wallet
```

The CLI never handles private keys directly. All signing is delegated to the OWS process via `ows sign tx`.

> **Testnet ETH required for gas.** Sepolia faucets: [alchemy.com/faucets](https://www.alchemy.com/faucets/ethereum-sepolia), [sepoliafaucet.com](https://sepoliafaucet.com)

---

## Read Commands

No wallet needed. Work immediately after install.

### Pool & Protocol

```bash
nile pool state                    # Pool metrics: TVL, utilization, share price, exposure
nile pool transactions             # Historical vault deposits and withdrawals
nile vault state                   # Alias for `nile pool state`
nile protocol mode                 # Operating mode: NORMAL, DEGRADED, REDUCE_ONLY, PAUSED
nile stats daily --days 7          # Daily volume, fees, position opens/closes
```

### Positions

```bash
nile position list --account <address>       # All positions for an account
nile position get --id <id>                  # Single position with real-time PnL
nile position search --side 0                # Search all positions (0=LONG, 1=SHORT)
```

### Oracle & Pricing

```bash
nile oracle price --tenor 1M       # Forward price for a specific tenor
nile oracle state                  # Full oracle state: spot, all tenors, validity
```

### Accounts & Tokens

```bash
nile account balance --account <address>                    # Margin account: collateral, locked, available
nile token balance --account <address>                      # USDC balance
nile token allowance --owner <owner> --spender <spender>    # ERC-20 allowance
```

### Analytics

```bash
nile fees list --first 25                       # Fee events (LIQUIDATION_PENALTY / EARLY_TERMINATION / MATURITY / TRADING)
nile buckets list --pair EUR/USD --first 25     # Per-(pair, maturity) net exposure cohorts
```

### Simulation

```bash
nile simulate open --side LONG --tenor 1M --notional 10000 --margin 500
# Preview margin, fee, entry strike for a new position
```

> **Note:** `simulate open` needs a configured wallet or `--from <address>` to run the on-chain eth_call. The margin math check runs without a wallet, but the full simulation requires a sender address.

### Output Formats

```bash
nile --format table pool state     # Human-readable table
nile --format json pool state      # JSON (default)
```

---

## Write Commands

Require wallet setup (see above). The CLI builds the transaction, delegates signing to OWS, and broadcasts.

### Trading

```bash
nile position open --side LONG --tenor 1M --notional 10000 --margin 20
nile position close --id <id>                                # Early termination
```

### Margin

```bash
nile account deposit --amount 1000       # Deposit 1,000 USDC as margin collateral
nile account withdraw --amount 500       # Withdraw 500 USDC available margin
```

### Vault (Liquidity Providers)

```bash
nile pool deposit --amount 5000
nile pool withdraw --amount 5000
nile vault deposit --amount 5000     # Alias for `nile pool deposit`
nile vault withdraw --amount 5000    # Alias for `nile pool withdraw`
```

### Token Operations

```bash
nile token approve --spender marginAccounts --amount 10000   # Approve USDC spending
nile token mint --to <address> --amount 10000                # Mint test USDC (testnet only)
```

All amounts are human-readable USDC. Example: `10000` = 10,000 USDC.
MCP tools use smallest unit (6 decimals) — the CLI handles conversion.

---

## Example: Open a Position

Complete flow from zero to confirmed position:

```bash
# 1. Check protocol mode
nile protocol mode --format table

# 2. Set wallet (one-time, after OWS setup)
nile config set-wallet my-wallet

# 3. Check USDC wallet balance
nile token balance --account 0xYOUR_ADDR --format table

# 4. Check margin account
nile account balance --account 0xYOUR_ADDR --format table

# 5. Deposit margin if needed (requires prior USDC approval)
nile token approve --spender marginAccounts --amount 1000
nile account deposit --amount 1000

# 6. Simulate the trade
nile simulate open --side short --tenor 1m --notional 10000 --margin 100 --format table

# 7. Open the position
nile position open --side short --tenor 1m --notional 10000 --margin 100

# 8. Verify
nile position get --id <ID> --format table
```

---

## Config Overrides

The CLI works zero-config for Sepolia. For advanced use cases (custom RPC, non-default deployment), override via config or flags.

### Persistent Config

Stored in `~/.nile/config.json`:

```bash
nile config show                   # Show current config
nile config set-rpc <url>          # Override default RPC URL
nile config set-subgraph <url>     # Override default subgraph URL
nile config set-signer <binary>    # Use a different signer binary (default: ows)
nile config set-wallet <name>      # Set default wallet name
```

### Per-Command Flags

```bash
nile --rpc-url https://custom-rpc.example.com pool state
nile --network sepolia position list <address>
```

### Environment Variables

| Variable | Description |
|----------|-------------|
| `NILE_RPC_URL` | RPC URL override |
| `NILE_SUBGRAPH_URL` | Subgraph URL override |
| `NILE_NETWORK` | Target network (default: `sepolia`) |
| `NILE_SIGNER` | Signer binary (default: `ows`) |
| `NILE_WALLET` | Wallet name |
| `NILE_FROM` | Sender address override (read-only/simulate commands) |
| `NILE_FORMAT` | Output format: `json` or `table` (default: `json`) |
| `NILE_ADDRESSES_FILE` | Path to custom addresses.json (overrides embedded addresses) |

### Resolution Order

For all configurable values: CLI flag > environment variable > `~/.nile/config.json` > embedded default.

---

## Embedded Defaults

The installed binary embeds these defaults from the [network config](https://mcp.nilemarkets.com/config/sepolia.json) at compile time:

| Setting | Embedded Value |
|---------|---------------|
| Network | `sepolia` (Ethereum Sepolia testnet) |
| RPC URL | Free public endpoint (overridable) |
| Subgraph URL | The Graph Studio hosted subgraph |
| Contract Addresses | All 10 Nile Markets contracts |

When the protocol redeploys contracts or updates the subgraph, install the latest CLI version to get the new embedded defaults:

```bash
npm install -g @nile-markets/cli@latest
# or
curl -fsSL https://mcp.nilemarkets.com/install.sh | bash
```

---

## Resources

- **Protocol docs**: [docs.nilemarkets.com](https://docs.nilemarkets.com)
- **MCP server**: [mcp.nilemarkets.com/skill.md](https://mcp.nilemarkets.com/skill.md)
- **Operation workflows**: [mcp.nilemarkets.com/workflow.md](https://mcp.nilemarkets.com/workflow.md)
- **Network config**: [mcp.nilemarkets.com/config/sepolia.json](https://mcp.nilemarkets.com/config/sepolia.json)
- **OWS wallet**: [docs.openwallet.sh](https://docs.openwallet.sh/)
