# Useful commands

## Key management

#### Add new key

```bash
sged keys add wallet
```

#### Recover existing key

```bash
sged keys add wallet --recover
```

#### List all keys

```bash
sged keys list
```

#### Delete key

```bash
sged keys delete wallet
```

#### Export key to the file

```bash
sged keys export wallet
```

#### Import key from the file

```bash
sged keys import wallet wallet.backup
```

#### Query wallet balance

```bash
sged q bank balances $(sged keys show wallet -a)
```

## Validator management

{% hint style="info" %}
Please make sure you have adjusted **moniker**, **identity**, **details** and **website** to match your values.
{% endhint %}

#### Create new validator

```bash
sged tx staking create-validator \
--amount 1000000usge \
--pubkey $(stchaind tendermint show-validator) \
--moniker "YOUR_MONIKER_NAME" \
--identity "YOUR_KEYBASE_ID" \
--details "YOUR_DETAILS" \
--website "YOUR_WEBSITE_URL" \
--chain-id sgenet-1 \
--commission-rate 0.05 \
--commission-max-rate 0.20 \
--commission-max-change-rate 0.01 \
--min-self-delegation 1 \
--from wallet \
--gas-adjustment 1.4 \
--gas auto \
--gas-prices 1000000000wei \
-y
```

#### Edit existing validator

```bash
sged tx staking edit-validator \
--new-moniker "YOUR_MONIKER_NAME" \
--identity "YOUR_KEYBASE_ID" \
--details "YOUR_DETAILS" \
--website "YOUR_WEBSITE_URL" \
--chain-id sgenet-1 \
--commission-rate 0.05 \
--from wallet \
--gas-adjustment 1.4 \
--gas auto \
--gas-prices 1000000000wei \
-y
```

#### Unjail validator

```bash
sged tx slashing unjail --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 10000000usge -y
```

#### Jail reason

```bash
sged query slashing signing-info $(sged tendermint show-validator)
```

#### List all active validators

```bash
sged q staking validators -oj --limit=3000 | jq '.validators[] | select(.status=="BOND_STATUS_BONDED")' | jq -r '(.tokens|tonumber/pow(10; 6)|floor|tostring) + " \t " + .description.moniker' | sort -gr | nl
```

#### List all inactive validators

```bash
sged q staking validators -oj --limit=3000 | jq '.validators[] | select(.status=="BOND_STATUS_UNBONDED")' | jq -r '(.tokens|tonumber/pow(10; 6)|floor|tostring) + " \t " + .description.moniker' | sort -gr | nl
```

#### View validator details

```bash
sged q staking validator $(sged keys show wallet --bech val -a)
```

## Token management

#### Withdraw rewards from all validators

```bash
sged tx distribution withdraw-all-rewards --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 1000000usge -y
```

#### Withdraw commission and rewards from your validator

```bash
sged tx distribution withdraw-rewards $(sged keys show wallet --bech val -a) --commission --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 1000000usge -y
```

#### Delegate tokens to yourself

```bash
sged tx staking delegate $(sged keys show wallet --bech val -a) 10000000usge --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 1000000usge -y
```

#### Delegate tokens to validator

```bash
sged tx staking delegate <TO_VALOPER_ADDRESS> 1000000usge --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 10000000usge -y
```

#### Redelegate tokens to another validator

```bash
sged tx staking redelegate $(sged keys show wallet --bech val -a) <TO_VALOPER_ADDRESS> 10000000usge --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 10000000usge -y
```

#### Unbond tokens from your validator

```bash
sged tx staking unbond $(sged keys show wallet --bech val -a) 1000000usge --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 10000000usge -y
```

#### Send tokens to the wallet

```bash
sged tx bank send wallet <TO_WALLET_ADDRESS> 1000000usge --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 10000000usge -y
```

## Governance

#### List all proposals

```bash
sged query gov proposals
```

#### View proposal by id

```bash
sged query gov proposal 1
```

#### Vote 'Yes'

```bash
sged tx gov vote 1 yes --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 10000000usge -y
```

#### Vote 'No'

```bash
sged tx gov vote 1 no --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 10000000usge -y
```

#### Vote 'Abstain'

```bash
sged tx gov vote 1 abstain --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 10000000usge -y
```

#### Vote 'NoWithVeto'

```bash
sged tx gov vote 1 NoWithVeto --from wallet --chain-id sgenet-1 --gas-adjustment 1.4 --gas auto --gas-prices 10000000usge -y
```

## Utility

#### Update ports

```bash
CUSTOM_PORT=110
sed -i -e "s%^proxy_app = \"tcp://127.0.0.1:26658\"%proxy_app = \"tcp://127.0.0.1:${CUSTOM_PORT}58\"%; s%^laddr = \"tcp://127.0.0.1:26657\"%laddr = \"tcp://127.0.0.1:${CUSTOM_PORT}57\"%; s%^pprof_laddr = \"localhost:6060\"%pprof_laddr = \"localhost:${CUSTOM_PORT}60\"%; s%^laddr = \"tcp://0.0.0.0:26656\"%laddr = \"tcp://0.0.0.0:${CUSTOM_PORT}56\"%; s%^prometheus_listen_addr = \":26660\"%prometheus_listen_addr = \":${CUSTOM_PORT}66\"%" $HOME/.sge/config/config.toml
sed -i -e "s%^address = \"tcp://0.0.0.0:1317\"%address = \"tcp://0.0.0.0:${CUSTOM_PORT}17\"%; s%^address = \":8080\"%address = \":${CUSTOM_PORT}80\"%; s%^address = \"0.0.0.0:9090\"%address = \"0.0.0.0:${CUSTOM_PORT}90\"%; s%^address = \"0.0.0.0:9091\"%address = \"0.0.0.0:${CUSTOM_PORT}91\"%" $HOME/.sge/config/app.toml
```

#### Update Indexer

**Disable indexer**

```bash
sed -i -e 's|^indexer *=.*|indexer = "null"|' $HOME/.sge/config/config.toml
```

**Enable indexer**

```bash
sed -i -e 's|^indexer *=.*|indexer = "kv"|' $HOME/.sge/config/config.toml
```

#### Update pruning

```bash
sed -i \
  -e 's|^pruning *=.*|pruning = "custom"|' \
  -e 's|^pruning-keep-recent *=.*|pruning-keep-recent = "100"|' \
  -e 's|^pruning-keep-every *=.*|pruning-keep-every = "0"|' \
  -e 's|^pruning-interval *=.*|pruning-interval = "19"|' \
  $HOME/.sge/config/app.toml
```

## 🚨 Maintenance

#### Get validator info

```bash
sged status 2>&1 | jq .ValidatorInfo
```

#### Get sync info

```bash
sged status 2>&1 | jq .SyncInfo
```

#### Get node peer

```bash
echo $(sged tendermint show-node-id)'@'$(curl -s ifconfig.me)':'$(cat $HOME/.sge/config/config.toml | sed -n '/Address to listen for incoming connection/{n;p;}' | sed 's/.*://; s/".*//')
```

#### Check if validator key is correct

```bash
[[ $(sged q staking validator $(sged keys show wallet --bech val -a) -oj | jq -r .consensus_pubkey.key) = $(stchaind status | jq -r .ValidatorInfo.PubKey.value) ]] && echo -e "\n\e[1m\e[32mTrue\e[0m\n" || echo -e "\n\e[1m\e[31mFalse\e[0m\n"
```

#### Get live peers

```bash
curl -sS http://localhost:26657/net_info | jq -r '.result.peers[] | "\(.node_info.id)@\(.remote_ip):\(.node_info.listen_addr)"' | awk -F ':' '{print $1":"$(NF)}'
```

#### Set minimum gas price

```bash
sed -i -e "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"1000000usge\"/" $HOME/.sge/config/app.toml
```

#### Enable prometheus

```bash
sed -i -e "s/prometheus = false/prometheus = true/" $HOME/.sge/config/config.toml
```

#### Reset chain data

```bash
sged tendermint unsafe-reset-all --keep-addr-book --home $HOME/.sge --keep-addr-book
```

#### Remove node

{% hint style="danger" %}
Please, before proceeding with the next step! All chain data will be lost! Make sure you have backed up your **priv\_validator\_key.json**!
{% endhint %}

```bash
cd $HOME
sudo systemctl stop sged
sudo systemctl disable sged
sudo rm /etc/systemd/system/sged.service
sudo systemctl daemon-reload
rm -f $(which sged)
rm -rf $HOME/.sge
rm -rf $HOME/sge
```

## Service Management

#### Reload service configuration

```bash
sudo systemctl daemon-reload
```

#### Enable service

```bash
sudo systemctl enable sged
```

#### Disable service

```bash
sudo systemctl disable sged
```

#### Start service

```bash
sudo systemctl start sged
```

#### Stop service

```bash
sudo systemctl stop sged
```

#### Restart service

```bash
sudo systemctl restart sged
```

#### Check service status

```bash
sudo systemctl status sged
```

#### Check service logs

```bash
sudo journalctl -u sged -f --no-hostname -o cat
```
