blockchain-cli/README.md
StillHammer 96b4dfa77b Initial setup: Rust CLI tool for blockchain node
- clap 4 CLI with wallet, tx, mine, block, chain commands
- reqwest HTTP client (REST API only, no lib dependency)
- Colored output with owo-colors + comfy-table
- Mining progress bar with indicatif
2026-02-01 10:12:30 +08:00

126 lines
3.0 KiB
Markdown

# 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
```bash
# Create a new wallet (keypair saved locally)
blockchain-cli wallet create
# Check balance
blockchain-cli wallet balance <ADDRESS>
```
### Transactions
```bash
# Send tokens
blockchain-cli tx send <FROM_ADDRESS> <TO_ADDRESS> <AMOUNT>
# View pending transactions
blockchain-cli tx pending
```
### Mining
```bash
# Mine pending transactions (with progress indicator)
blockchain-cli mine <MINER_ADDRESS>
```
### Blocks
```bash
# List recent blocks
blockchain-cli block list [--limit 10]
# Get block details
blockchain-cli block get <HASH>
```
### Chain
```bash
# 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
```bash
# 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`.
## Related Repos
- [blockchain-core](../blockchain-core) - Core library + REST API node
- [blockchain-flutter](../blockchain-flutter) - Flutter mobile/web app
## License
MIT