Interactive CLI Example
A full-featured interactive CLI for exploring Solana development with Chain Forge.
Overview
The Interactive CLI provides a menu-driven interface for:
- Deploy Node: Start a local Solana test validator with customizable settings
- Deploy Program: Build and deploy Solana programs interactively
- Send Funds: Transfer SOL between accounts
- Real-time Updates: See account balances update after transactions
Getting Started
Prerequisites
- Node.js 18+
- Yarn 4 (via Corepack:
corepack enable) - Solana CLI tools
- Rust and
cargo-build-sbffor building programs
Installation
bash
# From the repository root, build Chain Forge first
cargo build --workspace --release
# Install dependencies
cd examples/interactive-cli
yarn install
# Build TypeScript
yarn build
# Run the CLI
yarn startDevelopment Mode
bash
yarn devFeatures
Deploy Node
Configure and start a local Solana validator:
- Port: Choose the RPC port (default: 8899)
- Mnemonic: Use default test mnemonic, generate random, or enter custom
- Accounts: Number of pre-funded accounts (1-100)
- Balance: Initial SOL balance per account
Deploy Program
Build and deploy Solana programs from the programs/ directory:
- Select a program from discovered programs
- Choose a payer account
- Build automatically with
cargo build-sbfif needed - Deploy and see the Program ID
Send Funds
Transfer SOL between accounts:
- Select source account
- Select destination (another account or custom address)
- Enter amount
- Confirm and send
Sample Program
The programs/hello_chain_forge/ directory contains a ready-to-use sample program.
Building Manually
bash
yarn build:programProgram Instructions
| Instruction | Byte | Description |
|---|---|---|
| Initialize | 0 | Sets counter to 0 |
| Increment | 1 | Adds 1 to counter |
| Hello | 2+ | Logs greeting message |
Adding Your Own Programs
Create a new program in the programs/ directory:
bash
mkdir -p programs/my_program/srcCreate programs/my_program/Cargo.toml:
toml
[package]
name = "my_program"
version = "0.1.0"
edition = "2021"
[workspace]
[lib]
crate-type = ["cdylib", "lib"]
[dependencies]
solana-program = "2.0"Create programs/my_program/src/lib.rs with your program code.
The CLI will automatically discover programs in the programs/ directory.
Architecture
src/
├── index.ts # Main loop and SIGINT handling
├── types.ts # TypeScript interfaces
├── state.ts # Application state management
├── ui/
│ ├── header.ts # Status header display
│ ├── menus.ts # Menu definitions
│ └── formatters.ts # Output formatting utilities
├── actions/
│ ├── deploy-node.ts # Node deployment flow
│ ├── deploy-program.ts # Program build and deployment
│ └── send-funds.ts # SOL transfer flow
└── utils/
└── programs.ts # Program discovery utilitiesUI Design
The CLI displays a header with current state:
╔═══════════════════════════════════════════════════════════════╗
║ Chain Forge Interactive CLI ║
║ Nodes: 1 | Port: 8899 | Accounts: 5 ║
╠═══════════════════════════════════════════════════════════════╣
║ # │ Address │ Balance ║
║ 0 │ 7xKX...3mPq │ 100.00 ║
║ 1 │ 9aBC...7nRs │ 100.00 ║
║ ... ║
╠═══════════════════════════════════════════════════════════════╣
║ Programs: hello_chain_forge (4xYZ...8kLm) ║
╚═══════════════════════════════════════════════════════════════╝