# SatLayer CLI

The SatLayer CLI tool allows developers to deploy, update and query BVS. It is an useful tool during development and avoids the complication of interacting with BVS/SatLayer's core contracts using the raw `babylond` command.&#x20;

The SatLayer CLI tool is constructed on top of the ChainIO library, with just a minimal layer of code for handling user inputs. Everything the CLI can accomplish is also possible with [ChainIO](https://docs.satlayer.xyz/bvs-developers-1/developer-toolbox/satlayer-cli/chainio).

## Installing SatLayer CLI

The SatLayer CLI is written in the Go programming language. Hence the Go compiler is needed in order to build the CLI tool. Methods to install golang differ depending on the operating system you are using. Generally, please follow the instructions on the [Golang install page](https://go.dev/doc/install) to install the Go compiler.&#x20;

For Linux users, follow the installation instructions according to the distribution you are using. For Ubuntu and other Debian-based system, run:

```bash
sudo apt-get install golang-go
```

For Arch based systems, run:

```bash
sudo pacman -S go
```

For Fedora and other RHEL based systems, run:

```bash
sudo dnf install golang
```

With the Golang compiler installed, run the following to build the SatLayer CLI.

```bash
git clone https://github.com/satlayer/devnet-satlayer-cli
cd devnet-satlayer-cli

# Modify go.mod to as satlayer-api is not public yet (will be!)
echo "\nreplace github.com/satlayer/satlayer-api v0.3.0 => /path/to/your/clone/of/devnet-satlayer-api" >> go.mod
go build
```

By default the `satlayer-cli` uses the `os` keyring backend. This allows key sharing between the Babylon command line and `satlayer-cli`. Enabling seamless inter-operation. Please refer to [Cosmos's Keyring document](https://docs.cosmos.network/v0.46/run-node/keyring.html) for details.

### Installation

`satlayer-cli` can be installed by running `go install`. This installs the built result into golang's default installation directory.&#x20;

```bash
go install
```

This installs to `$HOME/go/bin`. Please make sure to have this path added to your [PATH environment variable.](https://en.wikipedia.org/wiki/PATH_\(variable\))  Please make sure the directory is in your system's `PATH` environment variable. For UNIX users (Linux, MacOS, etc..)

```bash
# ~/.bashrc or ~/.zshrc
export PATH=$HOME/go/bin:$PATH
```

Then `source` your shell rc scrip or start a new shell to active it.

```bash
source ~/.bashrc
# or
source ~/.zshrc
```

On 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.

```powershell
# 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.

### Configuration

By default the configuration file is stored in `$HOME/.config/satlayer/config.toml`(or `%USERPROFILE%\.config\satlayer\config.toml` on Windows). You can set the `SATLAYER_CONFIG` environment variable to change where the configuration is loaded from. There is no need to set this variable if you wish to use the default configuration file path.

On \*NIX (Linux, MacOS, etc..), assuming a BASH or DASH compatible shell:

```bash
# Demo command. the ... at the end is the rest of the command you wish to run
SATLAYER_CONFIG=/path/to/your/config.toml ./satlayer-cli ...
```

On Windows, or using PowerShell on \*NIX, remember to `Remove-Item` afterwards as PowerShell does not support temporary variables.

```powershell
# Demo command. the ... at the end is the rest of the command you wish to run
$env:SATLAYER_CONFIG = "C:\path\to\your\config.toml"; ./satlayer-cli ...
Remove-Item env\SATLAYER_CONFIG
```

## Command Structure

The SatLayer CLI is a monolithic program (in opposite to how most classic UNIX commands) with layered sub-commands.&#x20;

Commands are in the format of the following.&#x20;

* Subcommands could be layered and flags follows the UNIX convention. A double dash (`--`) is used for long names and a single dash (`-`) is used for short, single character flags and options. &#x20;

```bash
./satlayer-cli [subcommand 1 [subcommand 2 [subcommand 3] ...]] [-f --flags]  
```

#### Notation conversion

We follow the convention of what is used by most GNU and BSD commands:

* Optional parameters are enclosed in `[square-brackets]`
* Required parameters are free-formed `without-any-decoration`
* Template/string expected to be provided by user is in `<angle-brackets>`
* Flags/options can be followed by zero or more parameters. For example
  * `-v` in a flag with no parameters
  * `-f <path-to-file>`is an option that accepts a parameter
  * `-c <files>...` indicates it accepts multiple parameters

For example, `my-command read -f <path-to-file> [-v]` indicates:

* The command name is `my-command`
* The subcommand is `read` and is mandatory
* The `-f` option is required and it is followed by a path to a file
* And the `-v` option is optional without any parameter following it.

## Built-in help

Every command and sub-commands of the SatLayer CLI includes built-in help message for quick access.&#x20;

They can be displayed by either running the `help` subcommand or via the `--help` or `-h` flag. They generally follow the same notation used in this document.&#x20;

For example:

```bash
❯ ./satlayer-cli chain -h
Chain related commands

Usage:
  satlayer chain [command]

Available Commands:
  get-account To query the account.
  get-node    To query the node status info.
  get-txn     To query the transaction.

Flags:
  -h, --help   help for chain
```

## Common parameters

The `user-key-name` parameter is very common among commands. To reduce the amount of text in the document. The option will not be described in each command documentation. `user-key-name` is a mandatory parameter that specifies which key in the keyring is used to invoke a contract.&#x20;
