Rust CLI tool for interacting with the blockchain node via REST API. clap 4, reqwest, colored output.
Go to file
2026-02-01 10:18:21 +08:00
src Initial setup: Rust CLI tool for blockchain node 2026-02-01 10:12:30 +08:00
.gitignore Initial setup: Rust CLI tool for blockchain node 2026-02-01 10:12:30 +08:00
Cargo.toml Initial setup: Rust CLI tool for blockchain node 2026-02-01 10:12:30 +08:00
CLAUDE.md Add CLAUDE.md project context 2026-02-01 10:18:21 +08:00
README.md Initial setup: Rust CLI tool for blockchain node 2026-02-01 10:12:30 +08:00

blockchain-cli

Rust command-line tool for interacting with the blockchain node. Communicates entirely via REST API - no direct library dependency on blockchain-core.

Architecture

blockchain-cli/
└── src/
    ├── main.rs             # Clap parsing + command dispatch
    ├── commands/
    │   ├── mod.rs          # Command enum (subcommands)
    │   ├── wallet.rs       # create, balance, list
    │   ├── transaction.rs  # send, list-pending
    │   ├── mining.rs       # mine (with progress bar)
    │   ├── blocks.rs       # list, get
    │   └── node.rs         # info, validate
    ├── client.rs           # NodeClient (reqwest HTTP wrapper)
    ├── display.rs          # Colored/formatted terminal output
    ├── config.rs           # Node URL, wallet directory
    └── error.rs            # CLI error types (anyhow)

Commands

USAGE:
    blockchain-cli [OPTIONS] <COMMAND>

COMMANDS:
    wallet    Wallet management
    tx        Transaction operations
    mine      Mine a new block
    block     Block explorer
    chain     Chain information

OPTIONS:
    --node <URL>    Node URL [default: http://localhost:3000]
    -h, --help      Print help
    -V, --version   Print version

Wallet

# Create a new wallet (keypair saved locally)
blockchain-cli wallet create

# Check balance
blockchain-cli wallet balance <ADDRESS>

Transactions

# Send tokens
blockchain-cli tx send <FROM_ADDRESS> <TO_ADDRESS> <AMOUNT>

# View pending transactions
blockchain-cli tx pending

Mining

# Mine pending transactions (with progress indicator)
blockchain-cli mine <MINER_ADDRESS>

Blocks

# List recent blocks
blockchain-cli block list [--limit 10]

# Get block details
blockchain-cli block get <HASH>

Chain

# Chain info (height, difficulty, latest hash)
blockchain-cli chain info

# Validate entire chain
blockchain-cli chain validate

Design Decisions

Decision Choice Rationale
CLI framework clap 4 (derive) Industry standard, excellent UX
HTTP client reqwest Async, well-maintained
Output owo-colors + comfy-table Colored text + formatted tables
Progress indicatif Mining progress bar
Errors anyhow Convenient error chaining for CLI
Node coupling REST API only Fully decoupled from core lib

Quick Start

# Build
cargo build --release

# Start blockchain-node first (see blockchain-core repo)
# Then use the CLI:
blockchain-cli chain info
blockchain-cli wallet create
blockchain-cli mine <YOUR_ADDRESS>

Configuration

The CLI looks for wallets in ~/.blockchain-cli/wallets/. Node URL defaults to http://localhost:3000 and can be overridden with --node.

License

MIT