Configuration
This guide explains how to configure BBAChain CLI and applications using configuration files and environment variables.
Table of Contents
- Configuration Methods
- Configuration File
- Environment Variables
- Configuration Priority
- Examples
- Security Best Practices
Configuration Methods
BBAChain supports two methods for configuration:
- Configuration File: Create a JSON or YAML file with your settings
- Environment Variables: Set environment variables in your shell
You can use either method or both together. Environment variables will override configuration file settings.
Configuration File
Creating a Configuration File
Create a configuration file named config.json (or config.yml for YAML) in your project directory or home directory.
Configuration Options
Here's an example configuration file with all available options:
{
"network": "testnet",
"rpcUrl": "https://api-testnet.bbachain.com",
"websocketUrl": "wss://api-testnet.bbachain.com/",
"privateKey": "your-private-key-here",
"keypairPath": "~/.bbachain/id.json",
"commitment": "confirmed",
"gasPrice": "20000000000",
"gasLimit": "21000"
}
Configuration Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
network | string | Network to connect to (mainnet or testnet) | "testnet" |
rpcUrl | string | RPC endpoint URL | "https://api-testnet.bbachain.com" |
websocketUrl | string | WebSocket endpoint URL | "wss://api-testnet.bbachain.com/" |
privateKey | string | Private key for signing transactions | "your-private-key" |
keypairPath | string | Path to keypair file | "~/.bbachain/id.json" |
commitment | string | Commitment level (processed, confirmed, finalized) | "confirmed" |
gasPrice | string | Gas price for transactions | "20000000000" |
gasLimit | string | Gas limit for transactions | "21000" |
You don't need to specify all parameters. Only include the ones you want to configure.
Using the Configuration File
Once you've created your configuration file, use it with the CLI:
bbachain-cli --config config.json
Or specify the full path:
bbachain-cli --config /path/to/config.json
Environment Variables
Environment variables provide an alternative way to configure BBAChain, which is useful for:
- CI/CD pipelines
- Docker containers
- Production deployments
- Avoiding storing secrets in files
Supported Environment Variables
| Environment Variable | Description | Example |
|---|---|---|
BBACHAIN_NETWORK | Network to connect to | mainnet or testnet |
BBACHAIN_RPC_URL | RPC endpoint URL | https://api-mainnet.bbachain.com |
BBACHAIN_WEBSOCKET_URL | WebSocket endpoint URL | wss://api-mainnet.bbachain.com/ |
BBACHAIN_PRIVATE_KEY | Private key for signing | your-private-key |
BBACHAIN_KEYPAIR_PATH | Path to keypair file | ~/.bbachain/id.json |
BBACHAIN_COMMITMENT | Commitment level | confirmed |
BBACHAIN_GAS_PRICE | Gas price | 20000000000 |
BBACHAIN_GAS_LIMIT | Gas limit | 21000 |
Setting Environment Variables
Linux/macOS
export BBACHAIN_NETWORK=testnet
export BBACHAIN_RPC_URL=https://api-testnet.bbachain.com
export BBACHAIN_PRIVATE_KEY=your-private-key
export BBACHAIN_GAS_PRICE=20000000000
export BBACHAIN_GAS_LIMIT=21000
Windows (PowerShell)
$env:BBACHAIN_NETWORK="testnet"
$env:BBACHAIN_RPC_URL="https://api-testnet.bbachain.com"
$env:BBACHAIN_PRIVATE_KEY="your-private-key"
$env:BBACHAIN_GAS_PRICE="20000000000"
$env:BBACHAIN_GAS_LIMIT="21000"
Windows (Command Prompt)
set BBACHAIN_NETWORK=testnet
set BBACHAIN_RPC_URL=https://api-testnet.bbachain.com
set BBACHAIN_PRIVATE_KEY=your-private-key
set BBACHAIN_GAS_PRICE=20000000000
set BBACHAIN_GAS_LIMIT=21000
Using Environment Variables
After setting environment variables, you can run the CLI without specifying a config file:
bbachain-cli
The CLI will automatically use the environment variables.
Configuration Priority
When both configuration file and environment variables are set, the priority is:
- Environment Variables (highest priority)
- Configuration File
- Default Values (lowest priority)
This means environment variables will always override configuration file settings.
Examples
Example 1: Testnet Development
Configuration File (config.json):
{
"network": "testnet",
"rpcUrl": "https://api-testnet.bbachain.com",
"commitment": "confirmed"
}
Usage:
bbachain-cli --config config.json
Example 2: Mainnet Production
Environment Variables:
export BBACHAIN_NETWORK=mainnet
export BBACHAIN_RPC_URL=https://api-mainnet.bbachain.com
export BBACHAIN_COMMITMENT=finalized
Usage:
bbachain-cli
Example 3: Mixed Configuration
Configuration File (config.json):
{
"network": "testnet",
"rpcUrl": "https://api-testnet.bbachain.com"
}
Environment Variable (overrides network):
export BBACHAIN_NETWORK=mainnet
bbachain-cli --config config.json
In this case, the CLI will use mainnet (from environment variable) but https://api-testnet.bbachain.com (from config file). You should ensure consistency between your settings.
Security Best Practices
Protecting Private Keys
Never expose your private key in code, configuration files, or version control!
Recommended Practices:
- Use Environment Variables: Store private keys in environment variables, not in files
- Use Keypair Files: Store keypairs in secure files with proper permissions
- Never Commit Secrets: Add configuration files with secrets to
.gitignore - Use Key Management Services: For production, consider using key management services
Example .gitignore
# Configuration files with secrets
config.json
*.key
*.pem
id.json
Setting File Permissions
If you must store keypairs in files, set restrictive permissions:
chmod 600 ~/.bbachain/id.json
Using Keypair Paths
Instead of storing private keys directly, use keypair file paths:
{
"keypairPath": "~/.bbachain/id.json"
}
This is more secure than storing the private key as a string.
Verifying Configuration
You can verify your configuration using:
bbachain config get
This will display your current configuration:
Config File: /home/user/.bbachain/cli/config.yml
RPC URL: https://api-testnet.bbachain.com
WebSocket URL: wss://api-testnet.bbachain.com/ (computed)
Keypair Path: /home/user/.bbachain/id.json
Commitment: confirmed
Related Topics
- Learn about BBAChain networks (Mainnet vs Testnet)
- Install the BBAChain CLI
- Understand consensus and commitment levels
- Set up a validator node
Next Steps:
- Configure for Testnet development
- Set up for Mainnet production
- Learn about validator configuration