February 21, 2023

Cosmos shortcuts

Get binaries (build):

git clone https://repo

cd repo

git remote add upstream https://repo

git fetch upstream

git checkout <testnet-bracnh>

make install

Change pruning to custom:

# Set working directory
export WD="<dir>"
export binary="<bin>"
export MONIKER="<me>"
export CHAIN_ID="<v0.1>"

# export WD=".babylond"
# export binary="babylond"
# export MONIKER="fackblock"
# export CHAIN_ID="bbn-test1"

$binary init $MONIKER --chain-id $CHAIN_ID

pruning="custom"
pruning_keep_recent="1000"
pruning_interval="10"
sed -i -e "s/^pruning *=.*/pruning = \"$pruning\"/" $HOME/$WD/config/app.toml
sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"$pruning_keep_recent\"/" $HOME/$WD/config/app.toml
sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"$pruning_interval\"/" $HOME/$WD/config/app.toml

Change ports ($WD needs to be set):

export port26658="<36658>"
export port26657="<36657>"
export port26656="<36656>"
export port26660="<36660>"
export port6060="<6061>"
export port9090="<9190>"
export port9091="<9191>"
export port1317="<1327>"

# config.toml
sed -i.bak -e "s%^proxy_app = \"tcp://127.0.0.1:26658\"%proxy_app = \"tcp://127.0.0.1:$port26658\"%; s%^laddr = \"tcp://127.0.0.1:26657\"%laddr = \"tcp://127.0.0.1:$port26657\"%; s%^pprof_laddr = \"localhost:6060\"%pprof_laddr = \"localhost:$port6060\"%; s%^laddr = \"tcp://0.0.0.0:26656\"%laddr = \"tcp://0.0.0.0:$port26656\"%; s%^prometheus_listen_addr = \":26660\"%prometheus_listen_addr = \":$port26660\"%" $HOME/$WD/config/config.toml
# app.toml
sed -i.bak -e "s%^address = \"0.0.0.0:9090\"%address = \"0.0.0.0:$port9090\"%; s%^address = \"0.0.0.0:9091\"%address = \"0.0.0.0:$port9091\"%; s%^address = \"tcp://0.0.0.0:1317\"%address = \"tcp://0.0.0.0:$port1317\"%" $HOME/$WD/config/app.toml
# client.toml
sed -i.bak -e "s%^node = \"tcp://localhost:26657\"%node = \"tcp://localhost:$port26657\"%" $HOME/$WD/config/client.toml
external_address=$(wget -qO- eth0.me)
sed -i.bak -e "s/^external_address *=.*/external_address = \"$external_address:$port26656\"/" $HOME/$WD/config/config.toml

echo "26656=$port26656,26657=$port26657,26658=$port26658,26660=$port26660,6060=$port6060,9090=$port9090,9091=$port9091,1317=$port1317" > $HOME/$WD/.custom-ports.txt 

Change chain and keyring:

$binary config chain-id $CHAIN_ID

$binary config keyring-backend os

$binary tendermint unsafe-reset-all --home $HOME/$WD

Seeds & Peers:

peers=""
sed -i.bak -e "s/^persistent_peers *=.*/persistent_peers = \"$peers\"/" $HOME/$WD/config/config.toml

seeds=""
sed -i.bak -e "s/^seeds =.*/seeds = \"$seeds\"/" $HOME/$WD/config/config.toml

sed -i 's/max_num_inbound_peers =.*/max_num_inbound_peers = 50/g' $HOME/$WD/config/config.toml
sed -i 's/max_num_outbound_peers =.*/max_num_outbound_peers = 25/g' $HOME/$WD/config/config.toml

sed -i -e "s/^filter_peers *=.*/filter_peers = \"true\"/" $HOME/$WD/config/config.toml

Download genesis:

<>
mv genesis.json ~/$WD/config/genesis.json

Start service:

tee /etc/systemd/system/$binary.service > /dev/null <<EOF
[Unit]
Description=$binary service
After=network-online.target

[Service]
User=$USER
ExecStart=$(which $binary) start
Restart=on-failure
RestartSec=3
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable $binary
systemctl restart $binary && journalctl -u $binary -f -o cat

Wallet:

# create
$binary keys add <name_wallet> --keyring-backend os

# create
$binary keys add <name_wallet> --recover --keyring-backend os

Validator:

$binary tx staking create-validator \
--commission-rate 0.1 \
--commission-max-rate 0.2 \
--commission-max-change-rate 0.1 \
--min-self-delegation "1000000" \
--amount 1000000<wei> \
--pubkey $($binary tendermint show-validator) \
--moniker $MONIKER \
--from $wallet \
--fees 5000<wei>

Status:

journalctl -u $binary -f -o cat
curl localhost:$port26657/status | jq