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

# CLI

> Use the repository private-transfer CLI script for delegate/send/claim flows

This project includes a repository script CLI (not a published npm binary):

* `scripts/telegram-private-transfer.ts`

## Command Syntax

```bash theme={null}
bun scripts/telegram-private-transfer.ts <delegate|send|subscribe|claim|undelegate>
```

## Prerequisites

* Build Anchor artifacts so `target/idl/*` and `target/types/*` exist:

```bash theme={null}
anchor build
```

* Provide valid signer keypairs (`SENDER_KEYPAIR`, `CLAIMER_KEYPAIR`) or use `~/.config/solana/id.json` defaults.
* Configure base and ephemeral RPC endpoints as needed.

## Commands

* `delegate`: initializes/funds sender deposit, ensures username deposit, creates permissions, delegates both deposits.
* `send`: executes `transferToUsernameDeposit` on PER.
* `subscribe`: watches username deposit updates on PER until interrupted (or until `TARGET_AMOUNT`).
* `claim`: claims from username deposit to recipient ATA using verified Telegram session.
* `undelegate`: commits and undelegates sender + username deposits back to base.

## Important Environment Variables

* `PROVIDER_ENDPOINT` / `ANCHOR_PROVIDER_URL`: base RPC (default `http://127.0.0.1:8899`)
* `WS_ENDPOINT`: base WS (default derived from base RPC)
* `EPHEMERAL_PROVIDER_ENDPOINT`: PER RPC (default `http://127.0.0.1:7799`)
* `EPHEMERAL_WS_ENDPOINT`: PER WS (default `ws://127.0.0.1:7800` for local)
* `EPHEMERAL_AUTH`: set `true` to request MagicBlock auth token for hosted PER
* `ER_VALIDATOR`: validator pubkey (default from script)
* `SENDER_KEYPAIR`, `CLAIMER_KEYPAIR`: keypair file paths
* `TOKEN_MINT`: override mint; otherwise script reads/writes `STATE_PATH`
* `STATE_PATH`: defaults to `scripts/.state/telegram-private-transfer.json`
* `DEPOSIT_AMOUNT`, `SEND_AMOUNT`, `CLAIM_AMOUNT`, `TARGET_AMOUNT`: raw token amounts
* `AIRDROP`: if `true`, request localnet airdrop when balance is low

## End-to-End Example

```bash theme={null}
# 1) Delegate and prepare state
bun scripts/telegram-private-transfer.ts delegate

# 2) Optional watcher (run in a separate terminal)
bun scripts/telegram-private-transfer.ts subscribe

# 3) Send on PER
bun scripts/telegram-private-transfer.ts send

# 4) Claim to recipient ATA
bun scripts/telegram-private-transfer.ts claim

# 5) Commit + undelegate
bun scripts/telegram-private-transfer.ts undelegate
```

## Flow Mapping

The CLI commands map to SDK operations as follows:

| CLI Command  | SDK Operations                                                                                                                                                                  |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `delegate`   | `initializeDeposit` → `modifyBalance(increase)` → `initializeUsernameDeposit` → `createPermission` / `createUsernamePermission` → `delegateDeposit` / `delegateUsernameDeposit` |
| `send`       | `transferToUsernameDeposit` (on PER)                                                                                                                                            |
| `subscribe`  | `getEphemeralUsernameDeposit` polling                                                                                                                                           |
| `claim`      | `claimUsernameDepositToDeposit` (on PER)                                                                                                                                        |
| `undelegate` | `undelegateDeposit` / `undelegateUsernameDeposit` → `modifyBalance(decrease)`                                                                                                   |

## Notes

* `subscribe` listens for account changes and can auto-exit once `TARGET_AMOUNT` is reached.
* The script uses a state file to persist mint context between commands.
* This CLI is a repo operational tool and may evolve with program workflows.
