Skip to main content

Configuration

This guide explains how to configure BBAChain CLI and applications using configuration files and environment variables.

Table of Contents

Configuration Methods

BBAChain supports two methods for configuration:

  1. Configuration File: Create a JSON or YAML file with your settings
  2. 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

ParameterTypeDescriptionExample
networkstringNetwork to connect to (mainnet or testnet)"testnet"
rpcUrlstringRPC endpoint URL"https://api-testnet.bbachain.com"
websocketUrlstringWebSocket endpoint URL"wss://api-testnet.bbachain.com/"
privateKeystringPrivate key for signing transactions"your-private-key"
keypairPathstringPath to keypair file"~/.bbachain/id.json"
commitmentstringCommitment level (processed, confirmed, finalized)"confirmed"
gasPricestringGas price for transactions"20000000000"
gasLimitstringGas limit for transactions"21000"
info

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 VariableDescriptionExample
BBACHAIN_NETWORKNetwork to connect tomainnet or testnet
BBACHAIN_RPC_URLRPC endpoint URLhttps://api-mainnet.bbachain.com
BBACHAIN_WEBSOCKET_URLWebSocket endpoint URLwss://api-mainnet.bbachain.com/
BBACHAIN_PRIVATE_KEYPrivate key for signingyour-private-key
BBACHAIN_KEYPAIR_PATHPath to keypair file~/.bbachain/id.json
BBACHAIN_COMMITMENTCommitment levelconfirmed
BBACHAIN_GAS_PRICEGas price20000000000
BBACHAIN_GAS_LIMITGas limit21000

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:

  1. Environment Variables (highest priority)
  2. Configuration File
  3. 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

danger

Never expose your private key in code, configuration files, or version control!

Recommended Practices:

  1. Use Environment Variables: Store private keys in environment variables, not in files
  2. Use Keypair Files: Store keypairs in secure files with proper permissions
  3. Never Commit Secrets: Add configuration files with secrets to .gitignore
  4. 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

Next Steps: