thru-coin-flip-cli
v1.0.3
Published
๐ช A polished CLI for interacting with coin flip programs on the Thru blockchain
Maintainers
Readme
๐ช Thru Coin Flip CLI
A polished command-line interface for interacting with coin flip programs on the Thru blockchain.
โจ Features
- ๐ช Flip coins using blockchain entropy for randomness
- ๐ฎ Interactive mode for easy coin flipping
- โ๏ธ Configuration for custom program IDs
- ๐ Works instantly with pre-deployed program
๐ Setup
Prerequisites
- Node.js 16+
- Thru CLI installed and configured
Installation & Usage
# One-time use (no installation)
npx thru-coin-flip-cli@latest flip
# Interactive mode
npx thru-coin-flip-cli@latest interactive
# Or install globally
npm install -g thru-coin-flip-cli
coin-flip flip๐ Commands
coin-flip check
Verify that thru-cli is installed and system is ready.
coin-flip flip [--program <programId>]
Execute a coin flip. Uses built-in default program or custom program ID.
coin-flip config [--show] [--set <programId>]
Manage default program ID configuration.
coin-flip interactive
Start interactive mode for easy coin flipping.
๐ฒ How It Works
The coin flip program uses blockchain entropy for randomness:
- Entropy Sources: Combines parent block hash, state root, block time, slot, transaction signature, and nonce
- SHA256 Hashing: Creates deterministic hash from multiple entropy sources
- Fair Result: Uses least significant bit for 50/50 probability
- Event Emission: Results are permanently recorded on-chain
- Verification: All entropy sources are publicly verifiable
๐ Project Structure
thru-programs/
โโโ src/ # TypeScript CLI source
โ โโโ cli.ts # Main CLI interface
โ โโโ utils.ts # Thru CLI wrapper utilities
โ โโโ types.ts # TypeScript definitions
โโโ coin_flip.c # C program source
โโโ coin_flip.h # C program header
โโโ GNUmakefile # Tutorial-style makefile
โโโ Local.mk # SDK build configuration
โโโ build/ # Compiled artifacts
โโโ thruvm/bin/ # Program binaries๐ง Development
# Run in development mode
npm run dev
# Build TypeScript
npm run build
# Build C program
npm run build-program
# Clean all builds
npm run clean๐ก Examples
Basic Usage
# Quick flip with default program
coin-flip flip
# Flip using specific program
coin-flip flip --program ta8xK9mNcP2wQ5...
# Interactive mode
coin-flip interactiveConfiguration
# View current config
coin-flip config --show
# Set custom default program
coin-flip config --set ta8xK9mNcP2wQ5...๐ Technical Details
- Language: C program compiled to RISC-V bytecode
- Blockchain: Thru testnet with zero-fee transactions
- Randomness: Cryptographically secure blockchain entropy
- CLI: TypeScript with Commander.js framework
- Build System: Thru SDK makefile with proper linking
๐ฏ Result Format
๐ฒ COIN FLIP RESULT ๐ฒ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Result: HEADS
Slot: 756
Signature: tsJDG61YPxWfmKQj...
Compute Units: 44,445
Events: 1 emitted
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๐ก Randomness
The coin flip uses blockchain-based randomness:
- Entropy comes from blockchain data (not user-controllable)
- SHA256 ensures deterministic but unpredictable results
- All data sources are publicly verifiable on-chain
- Program logic is open source and auditable
๐ License
MIT - Feel free to use and modify for your projects.
Built with โค๏ธ for the Thru blockchain ecosystem
