Babylon CLI
Babylon Chain's Command Line Tool
As SatLayer is built on Babylon, we will often need to interact with Babylon Chain. Sometimes we need to utilize the low-level cli tool babylond
during development. This document serves as a centralized resource for getting and installing babylond
as well as commonly used operations.
Please note that this is not an exhaustive list of the commands supported by Babylon.
Installing babylond
In order to compile Babylon, Go >= 1.21
should be installed. Methods to install golang differ depending on the operating system you are using. Generally, please follow the instructions on the Golang install page to install the Go compiler.
For Linux users, follow the installation instructions according to the distribution you are using. For Ubuntu and other Debian-based system, run:
sudo apt-get install golang-go
For Arch based systems, run:
sudo pacman -S go
For Fedora and other RHEL based systems, run:
sudo dnf install golang
Clone Babylon source code repo and
cd
into the directory
git clone https://github.com/babylonchain/babylon.git
cd babylon
To build the binary, execute
make build
After compiling, you can find the binary in ./build/babylond
.
Install babylond
To install the binary to your user's directories, execute the following. This command installs babylond
to Golang's default install directory $HOME/go/bin
. Please make sure to have this path added to your PATH environment variable.
make install
Then add $HOME/go/bin
to PATH
. For UNIX users (Linux, MacOS, etc..)
# ~/.bashrc or ~/.zshrc
export PATH=$HOME/go/bin:$PATH
Then source
your shell rc scrip or start a new shell to active it.
source ~/.bashrc
# or
source ~/.zshrc
Or Windows or UNIX with PowerShell you should edit the $profile
file (run echo $profile
in PowerShell to acquire the file path) and append the following.
# Edit $profile
$env:Path = $env:UserProfile+[IO.Path]::PathSeparator+"go"+[IO.Path]::PathSeparator+"bin;"+$env:Path
Close and start a new PowerShell session to activate the change.
Key Operations
babylond
allows the management of keys. Common operations include create, delete, export, import and listing keys. Multiple keyring backends are supported.
By default, babylond
asks the OS to handle key storage. But other options are available, mostly for development purposes.
# Create a new key under the name `wallet_name`, stored by the OS
./babylond keys add ${wallet_name} --keyring-backend os --keyring-dir ./
Flag explanation:
--keyring-backend: Select keyring backend (os|file|kwallet|pass|test|memory) (default "os").
--keyring-dir: The client Keyring directory; if omitted, the "default" home directory will be used.
Deleting Keys
To delete keys, run this command:
# Delete the given key:
./babylond keys delete ${wallet_name}
Printing keys
The keys export
sub-comamnd prints the key:
# Export private keys:
./babylond keys export ${wallet_name} --output json
Flag explanation:
--output: Output format (text|json) (default "text").
Importing keys
Key import is also supported via this command:
# Import private keys into the local keybase:
./babylond keys import
Listing keys
To list all keys stored in the keyring:
# List all keys:
./babylond keys list
Query
query
houses subcommands that queries specific information. The most common queries are for account balances, transaction information and smart contract states. These operations requires communication with a Babylon node. The --node
parameter specifics the Babylon (RPC) node to use. And the --chain-id
specifics the chain ID. For testnet, these 2 parameters must be specified correctly in order for the command to work at all.
# Query native token balances:
./babylond query bank balances ${wallet_address} --chain-id ${chain_id} --node ${rpc}
Flag explanation:
--chain-id: The network id.
--node: CometBFT rpc interface for the chain.
To query a past transaction
# Query tx hash:
./babylond query tx ${tx_hash} --log_format=json --node ${rpc}
Flag explanation:
--log_format: The logging format (json|plain) (default "plain")
To query the state of a smart contract
# This command queries the state of a smart contract. Calls contract with given address with querying data and prints the returned result
./babylond query wasm contract-state smart ${contract_address} ${json_encoded_init_args} --log_format=json --node ${rpc}
CosmWasm
Babylon supports CosmWasm smart contracts. The wasm
subcommands deals with related operations.
Like the query
subcommand above, --node
and --chain-id
are needed when use on a testnet. In addition, they are required for gas controlling parameters to limit the maximal gas spent on the operation.
# Upload a wasm binary:
./babylond tx wasm store ${wasm_directory} --from=${wallet_name} --gas=auto --gas-prices=1ubbn --gas-adjustment=1.3 --chain-id=${chain_id} -b=sync --yes --log_format=json --node ${rpc}
Flag explanation:
--from: Name or address of private key with which to sign.
--gas: Gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically.
--gas-prices: Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom).
--gas-adjustment: Adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored.
-b, --broadcast-mode: Transaction broadcasting mode (sync|async) (default "sync").
-y, --yes: Skip tx broadcasting prompt confirmation.
After uploading the WASM binary, a contact needs to be instantiated from the binary:
# Instatiate a wasm contract:
./babylond tx wasm instantiate ${code_id} ${json_encoded_init_args} --from=${wallet_name} --no-admin --label=${contract_label} --gas=auto --gas-prices=1ubbn --gas-adjustment=1.3 --chain-id=${chain_id} -b=sync --yes --log_format=json --node ${rpc}
Flag explanation:
--label: A human-readable name for this contract in lists.
CosmWasm contracts separate query and execute functions, distinguishing between read-only and mutable operations. Queries are free, while executing a contract requires gas.
# Execute a command on a wasm contract:
./babylond tx wasm execute ${contract_address} ${json_encoded_init_args} --from=${wallet_name} --gas=auto --gas-prices=1ubbn --gas-adjustment=1.3 --chain-id=${chain_id} -b=sync --yes --log_format=json --node ${rpc}
In addition, EVM and contracts on CosmWasm can be upgraded (if migrate
is enabled)
# Migrate a wasm contract to a new code version:
./babylond tx wasm migrate ${contract_address} ${new_code_id_int64} '{"migrate":{}}' --from=${wallet_name} --gas-prices=1ubbn --gas=auto --gas-adjustment=1.3 --chain-id=${chain_id} -b=sync --yes --log_format=json --node ${rpc}
Others
The tx bank send
command sends token from one address (you must own the private key) to another. The same node, chain and gas parameters apply here too.
# Transfer native tokens:
./babylond tx bank send ${from_address} ${to_address} ${amount} --node ${rpc} --keyring-backend ${keyring_backend} --keyring-dir ${keyring_dir} --chain-id=${chain_id} --fees 2ubbn
Flag explanation:
--fees: Fees to pay along with transaction; eg: 10uatom.
Reference
You can use ./babylond --help
to get full documentations about how to use babylon command line or through the official Babylon documentation.
Last updated
Was this helpful?