Thru CLI
A command-line interface for interacting with the Thru blockchain network. The Thru CLI provides access to RPC methods and program upload functionality, making it easy to query blockchain data and deploy programs.
Table of Contents
- Installation
- Quick Start
- Configuration
- Commands
- Usage Examples
- Output Formats
- Troubleshooting
- Security Considerations
Installation
From Source
# Clone the repository
# Build the CLI
# The binary will be available at target/release/thru-cli
# Optionally, install it to your PATH
Prerequisites
- Rust 1.70 or later
- Access to a Thru node RPC endpoint
Quick Start
- First Run: On first execution, the CLI will create a default configuration file:
This creates ~/.thru/cli/config.yaml with default settings.
- Configure Your Setup: Edit the configuration file to set your RPC endpoint and private key:
# Edit the config file
- Test Connection: Verify your setup by checking node health:
Configuration
The CLI uses a YAML configuration file located at ~/.thru/cli/config.yaml. This file is automatically created with default values on first run.
Configuration File Structure
# Thru CLI Configuration File
# This file contains settings for the Thru command-line interface
# RPC endpoint URL for connecting to the Thru node
rpc_base_url: "http://localhost:8080"
# Default private key (64-character hex string)
# WARNING: Keep this file secure and never share your private key
default_private_key: "0000000000000000000000000000000000000000000000000000000000000000"
# Public key of the uploader program
uploader_program_public_key: "taAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEB"
# Request timeout in seconds
timeout_seconds: 30
# Maximum number of retries for failed requests
max_retries: 3
# Optional authorization token for HTTP requests (sent as Bearer token)
# auth_token: "your-bearer-token-here"
Configuration Parameters
| Parameter | Description | Default | Required |
|---|---|---|---|
rpc_base_url |
Base URL for RPC requests | http://localhost:8080 |
Yes |
default_private_key |
Your private key (64-char hex) | All zeros (placeholder) | Yes |
uploader_program_public_key |
Uploader program public key | Default uploader | Yes |
timeout_seconds |
Request timeout | 30 | No |
max_retries |
Max retry attempts | 3 | No |
auth_token |
Authorization token for HTTP requests | None | No |
RPC URL and Port Handling
The CLI uses standard port handling:
- HTTP URLs without explicit port: Default to port
80(e.g.,http://localhost→http://localhost:80) - HTTPS URLs without explicit port: Default to port
443(e.g.,https://grpc.alphanet.thruput.org→https://grpc.alphanet.thruput.org:443) - Explicit ports: Used exactly as specified (e.g.,
http://localhost:8472uses port8472)
Examples:
# HTTPS with standard port (recommended for production)
rpc_base_url: "https://grpc.alphanet.thruput.org:443"
# HTTPS without explicit port (defaults to 443)
rpc_base_url: "https://grpc.alphanet.thruput.org"
# HTTP with custom port (common for local development)
rpc_base_url: "http://localhost:8472"
# HTTP without explicit port (defaults to 80)
rpc_base_url: "http://localhost"
Important: Do not use angle brackets <> around URLs in the config file.
Authentication
If your Thru node requires authentication, you can configure an authorization token in your config.yaml:
# Authentication example
rpc_base_url: "https://private.thru.io"
auth_token: "your-bearer-token-here"
The auth token will be sent as a Bearer token in the Authorization header for all HTTP requests and WebSocket connections to the RPC server.
Setting Up Your Private Key
⚠️ Security Warning: Never share your private key or commit it to version control.
- Generate a new private key (64 hex characters):
# Example: Generate a random private key
- Update your config file with the generated key:
default_private_key: "your_64_character_hex_private_key_here"
Commands
The CLI supports the following commands:
RPC Commands
getversion
Get version information from the Thru node.
gethealth
Get health status of the Thru node.
getaccountinfo
Get detailed account information for a specific account.
getbalance
Get balance for a specific account.
transfer
Transfer tokens between accounts.
Parameters:
<src>: Source key name from configuration<dst>: Destination (key name from config or public address in taXX format)<value>: Amount to transfer (must be greater than 0)
Program Commands
program upload
Upload a program to the blockchain.
Parameters:
--uploader <pubkey>: Optional custom uploader program public key<seed>: Seed string for account derivation<program_file>: Path to the program binary file
program cleanup
Clean up program accounts associated with a seed.
Parameters:
--uploader <pubkey>: Optional custom uploader program public key<seed>: Seed string for account derivation
Token Commands
token
Manage token programs and operations.
Global Options
--json: Output results in JSON format instead of human-readable format
Usage Examples
Basic RPC Operations
Check Node Version
# Human-readable output
# JSON output
{
}
Check Node Health
# Healthy node
# Unhealthy node
# JSON output
{
}
Get Account Information
# Human-readable output
# JSON output
{
}
Get Account Balance
# Human-readable output
# JSON output
{
}
Transfer Tokens
# Transfer using key names
# Transfer to public address
# JSON output
{
}
Program Operations
Upload a Program
# Upload example event emission program
)
# Now execute transaction against just uploaded program
)
)
)
# Upload with default uploader
)
)
# Upload with custom uploader
# JSON output
{
}
Clean Up Program Accounts
# Cleanup with default uploader
# JSON output
{
}
Output Formats
The CLI supports two output formats:
Human-Readable Format (Default)
- Colored output with clear labels
- Status indicators (green for success, red for errors)
- Formatted information with proper indentation
- Progress information for long operations
JSON Format (--json flag)
- Machine-readable structured output
- Consistent schema across all commands
- Suitable for scripting and automation
- Error information included in JSON structure
Error Handling
Both output formats handle errors gracefully:
# Human-readable error
# JSON error
{
}
Troubleshooting
Common Issues
1. Configuration File Not Found
Problem: CLI reports config file not found. Solution: Run any command to auto-generate the default config:
2. Connection Refused
Problem: Failed to get version: Connection refused
Solution:
- Check if your Thru node is running
- Verify the
rpc_base_urlin your config file - Ensure the RPC port is accessible
3. Invalid Private Key
Problem: Configuration error: Invalid private key
Solution:
- Ensure your private key is exactly 64 hexadecimal characters
- Generate a new key:
openssl rand -hex 32 - Update your config file with the new key
4. Account Not Found
Problem: Account not found for address: ...
Solution:
- Verify the account public key is correct
- Check if the account exists on the network
- Ensure you're connected to the correct network
5. Program File Not Found
Problem: Program file not found: ./program.bin
Solution:
- Check the file path is correct
- Ensure the file exists and is readable
- Use absolute path if relative path fails
6. Timeout Errors
Problem: Request timeouts during operations Solution:
- Increase
timeout_secondsin config - Check network connectivity
- Verify node is responsive
Debug Information
For debugging connection issues:
# Test basic connectivity
# Check config file location
# Validate config syntax
Getting Help
# Show help for main command
# Show help for program subcommands
# Show help for specific subcommand
thru-cli program --help
Show help for specific subcommand
thru-cli program upload --help
## Security Considerations
### Private Key Security
1. **File Permissions**: Ensure your config file has restricted permissions:
```bash
chmod 600 ~/.thru/cli/config.yaml
- Environment Variables: Consider using environment variables for sensitive data:
- Version Control: Never commit your config file with real private keys:
# Add to .gitignore
Network Security
- HTTPS: Use HTTPS endpoints for production:
rpc_base_url: "https://your-node.example.com"
- Firewall: Ensure your RPC endpoint is properly secured
- Authentication: Use proper authentication if required by your node
Best Practices
- Separate Keys: Use different private keys for different environments
- Regular Rotation: Rotate private keys periodically
- Backup: Securely backup your private keys
- Monitoring: Monitor account activity for unauthorized transactions
Program Upload Security
- Code Review: Always review program code before upload
- Testing: Test programs thoroughly on testnet first
- Verification: Verify program hashes match expected values
- Access Control: Use appropriate uploader program permissions
Advanced Usage
Scripting with JSON Output
The JSON output format makes the CLI suitable for scripting:
#!/bin/bash
# Check if node is healthy
HEALTH=
if [; then
fi
# Get account balance
BALANCE=
Batch Operations
# Check multiple account balances
for; do
done
Configuration Management
# Backup current config
# Use different config for different networks
Contributing
Contributions are welcome! Please see the main repository for contribution guidelines.
License
This project is licensed under MIT OR Apache-2.0.