# Open CLI

Ape Church is a fully on-chain, decentralized casino on <mark style="color:green;">**ApeChain**</mark><mark style="color:green;">.</mark> The <mark style="color:green;">**Ape Church Open CLI**</mark> lets you play Ape Church games directly from the terminal **permissionlessly**.

<mark style="color:green;">**What that means in practice:**</mark>

* No accounts
* No API keys
* No approvals
* Every wager is a **smart contract transaction** on ApeChain
* Randomness is **provably fair** via **Chainlink VRF**

This page explains how to install the CLI, set up a wallet, play games, automate sessions, and use JSON output for scripts and agents.

{% embed url="<https://drive.google.com/file/d/1OfsIY5nMzt3fM1-JnS_mpGtyZMaIbavE/view?usp=sharing>" %}

#### <mark style="color:green;">**Overview**</mark>

Most online casinos are walled gardens (logins, rate limits, anti-bot rules, centralized control). Ape Church is different:

* **Direct on-chain gameplay:** the CLI talks to contracts, not a private backend.
* **Automation is normal:** contracts don’t care if a human, script, or agent places a bet.
* **Composability:** transactions, game IDs, and results are easy to integrate into tools and workflows.

#### <mark style="color:green;">**Prerequisites**</mark>

* A terminal environment (local machine, VPS, container, etc.)
* **APE on ApeChain** to wager
* Enough balance to cover **wagers + network fees**

**About fees (plain language):** each game is an on-chain transaction, so you’ll pay small **network fees** (gas) and a **randomness fee** (VRF) in addition to your wager.

#### <mark style="color:green;">**Install the CLI**</mark>

```bash
npm install -g @ape-church/skill
```

Verify it’s installed:

```bash
apechurch --version
```

#### <mark style="color:green;">**Set Up Your Wallet**</mark>&#x20;

**1. Create a wallet and register a username**

```bash
apechurch install --username MY_AGENT
```

This creates a **self-custodial** wallet locally and prints your wallet address.

**2. Fund the wallet with APE on ApeChain**

Send/bridge APE to the address shown after install.

Bridge - <https://relay.link/bridge/apechain>

**3. Confirm everything is ready**

```bash
apechurch status
```

#### <mark style="color:green;">**Quickstart  - Play a Game**</mark>

Play once:

```bash
apechurch play
```

Run an automated session (loop mode):

```bash
apechurch play --loop
```

#### <mark style="color:green;">**Supported Games**</mark>

The CLI supports multiple game types: dice/odds games, table games, slots, keno-style games, matching games, and interactive card games.

List games:

```bash
apechurch games
```

<mark style="color:green;">**Quick Reference**</mark>&#x20;

* ApeStrong (dice/odds): `apechurch play ape-strong 10 50`
* Roulette: `apechurch play roulette 10 RED`
* Baccarat: `apechurch play baccarat 10 BANKER`
* Jungle Plinko: `apechurch play jungle-plinko 10 2 50`
* Keno: `apechurch play keno 10`
* Speed Keno: `apechurch play speed-keno 10 --picks 5 --games 20`
* Slots (Dino Dough): `apechurch play dino-dough 10 10`
* Monkey Match: `apechurch play monkey-match 10 --mode 2`
* Bear-A-Dice: `apechurch play bear-dice 10 --difficulty 1 --rolls 3`
* Blackjack (auto): `apechurch blackjack 10 --auto`
* Video Poker (auto): `apechurch video-poker 10 --auto`

<mark style="color:green;">**Automation: Loop Mode (with safety rails)**</mark>

Loop mode is designed for long-running sessions and unattended play.

**Basic loop**

```bash
apechurch play --loop
apechurch play --loop --delay 5
apechurch play ape-strong 10 50 --loop
```

**Safety Controls (recommended)**

Use these to prevent “runaway sessions”:

```bash
apechurch play --loop --target 200
apechurch play --loop --stop-loss 50
apechurch play --loop --max-games 100
```

Options:

* `--target <ape>`: stop when balance reaches a target
* `--stop-loss <ape>`: stop when balance drops to a limit
* `--max-games <n>`: stop after N games
* `--delay <sec>`: delay between games (default: 3)

<mark style="color:green;">**Betting Strategies (bet sizing)**</mark>

Strategies automatically adjust bet size based on win/loss patterns.

Available strategies:

* `flat` (default)
* `martingale` (high risk)
* `reverse-martingale`
* `fibonacci`
* `dalembert` (d'Alembert)

Example:

```bash
apechurch play roulette 10 RED --loop --bet-strategy martingale --max-bet 100
```

Safety options:

```bash
--max-bet <ape>
--stop-loss <ape>
```

{% hint style="info" %}
**Recommendation:** always set `--max-bet` when using progressive strategies (especially martingale).
{% endhint %}

<mark style="color:green;">**Blackjack & Video Poker (auto-play)**</mark>

Some games include an `--auto` mode that chooses actions using a mathematical decision engine.

**Blackjack**

```bash
apechurch blackjack 10 --auto
apechurch blackjack 10 --auto --loop --max-games 20
```

**Video Poker**

```bash
apechurch video-poker 10 --auto
apechurch video-poker 10 --auto --loop --max-games 50
```

<mark style="color:green;">**JSON Output (for Scripts, Bots, and Agents)**</mark>

All commands support machine-readable output with `--json`.

**Status**

```bash
apechurch status --json
```

Common fields include:

* `address`
* `balance`, `available_ape`, `gas_reserve_ape`
* `gp`
* `paused`
* `username`, `persona`
* `can_play`

**Play**

```bash
apechurch play --json
```

Play output includes:

* `tx` (transaction hash)
* `game_url`
* wager + config
* result (`won`, `payout_ape`, `pnl_ape`)

Errors are returned as:

```json
{ "error": "..." }
```

#### <mark style="color:green;">**Costs & Limits**</mark>&#x20;

Each game is an on-chain transaction, so you pay:

* **Gas** (varies by game complexity)
* **VRF/randomness fees** (varies)

Make sure your wallet has enough balance for wagers **and** fees, especially when running loop mode.

#### <mark style="color:green;">**Common Issues (Quick Fixes)**</mark>

* **“Insufficient balance” / session stops immediately**
  * You need enough APE for your **wager plus fees** (gas + VRF). Add more APE or lower your bet size.
* **Stuck or unexpected loop behavior**
  * Add guardrails like `--max-games`, `--stop-loss`, and a reasonable `--delay`.
* **Wallet safety concerns**
  * Encrypt your wallet (recommended) and never share/export the private key unless you fully understand the risk.

#### <mark style="color:green;">**Security: Protect Your Wallet**</mark>

Wallet file location:

* `~/.apechurch/wallet.json`

**Critical rules:**

* Never share your private key
* Never paste it into prompts or third-party tools
* Consider encrypting your wallet:

  ```bash
  apechurch wallet encrypt
  ```

<mark style="color:green;">**Updates**</mark>

```bash
npm update -g @ape-church/skill
apechurch --version
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ape.church/building/open-cli.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
