# Node Installation

## [EXPLORER](https://explorer.stavr.tech/C4E)

* Approximate **hardware requirements**:

| Node Type | CPU | RAM  | Storage |
| --------- | --- | ---- | ------- |
| Mainnet   | 8   | 16GB | 250GB   |

## 1) Auto\_install script

```bash
source <(curl -s https://raw.githubusercontent.com/111STAVR111/props/refs/heads/main/C4E/c4)
```

## 2) Manual installation

#### Preparing the server

```bash
sudo apt update && sudo apt upgrade -y
sudo apt install curl tar wget clang pkg-config libssl-dev jq build-essential bsdmainutils git make ncdu gcc git jq chrony liblz4-tool -y
```

### GO 1.21.6

```bash
ver="1.21.6"
wget "https://golang.org/dl/go$ver.linux-amd64.tar.gz"
sudo rm -rf /usr/local/go
sudo tar -C /usr/local -xzf "go$ver.linux-amd64.tar.gz"
rm "go$ver.linux-amd64.tar.gz"
echo "export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> $HOME/.bash_profile
source $HOME/.bash_profile
go version
```

## Build 10.10.24

```bash
cd $HOME && mkdir $HOME/go/bin/
git clone https://github.com/chain4energy/c4e-chain
cd c4e-chain
git checkout v1.4.3
make install
```

`c4ed version --long | grep -e commit -e version`

* version: 1.4.3
* commit: 608c6c21f7c12f7d5bcbfb8e045aa1b6cfb8fe1b

## Initiation

```python
c4ed init STAVR_guide --chain-id=perun-1
c4ed config chain-id perun-1
```

### Create/recover wallet

```bash
c4ed keys add <walletname>
           OR
c4ed keys add <walletname> --recover
```

### Download Genesis

```bash
wget -L -O $HOME/.c4e-chain/config/genesis.json https://server-1.stavr.tech/Mainnet/C4e/genesis.json
```

`sha256sum $HOME/.c4e-chain/config/genesis.json`

* 6c736993a681a6759d3ec41550995fe04f48dd332d03375d879f3b464c6ceabf

### Set up the minimum gas price and Peers/Seeds/Filter peers/MaxPeers

```bash
sed -i -e "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"0uc4e\"/" $HOME/.c4e-chain/config/app.toml
sed -i -e "s/^filter_peers *=.*/filter_peers = \"true\"/" $HOME/.c4e-chain/config/config.toml
external_address=$(wget -qO- eth0.me) 
sed -i.bak -e "s/^external_address *=.*/external_address = \"$external_address:26656\"/" $HOME/.c4e-chain/config/config.toml
peers=""
sed -i.bak -e "s/^persistent_peers *=.*/persistent_peers = \"$peers\"/" $HOME/.c4e-chain/config/config.toml
seeds=""
sed -i.bak -e "s/^seeds =.*/seeds = \"$seeds\"/" $HOME/.c4e-chain/config/config.toml
sed -i 's/max_num_inbound_peers =.*/max_num_inbound_peers = 50/g' $HOME/.c4e-chain/config/config.toml
sed -i 's/max_num_outbound_peers =.*/max_num_outbound_peers = 50/g' $HOME/.c4e-chain/config/config.toml
```

#### Pruning (optional)

```bash
pruning="custom"
pruning_keep_recent="1000"
pruning_keep_every="0"
pruning_interval="100"
sed -i -e "s/^pruning *=.*/pruning = \"$pruning\"/" $HOME/.c4e-chain/config/app.toml
sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"$pruning_keep_recent\"/" $HOME/.c4e-chain/config/app.toml
sed -i -e "s/^pruning-keep-every *=.*/pruning-keep-every = \"$pruning_keep_every\"/" $HOME/.c4e-chain/config/app.toml
sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"$pruning_interval\"/" $HOME/.c4e-chain/config/app.toml
```

#### Indexer (optional)

```bash
indexer="null" &&
sed -i -e "s/^indexer *=.*/indexer = \"$indexer\"/" $HOME/.c4e-chain/config/config.toml
```

### Download addrbook

```bash
wget -O $HOME/.c4e-chain/config/addrbook.json "https://server-1.stavr.tech/Mainnet/C4e/addrbook.json"
```

## Create a service file

```bash
sudo tee /etc/systemd/system/c4ed.service > /dev/null <<EOF
[Unit]
Description=c4e
After=network-online.target

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

[Install]
WantedBy=multi-user.target
EOF
```

## StateSync C4E Mainnet

```bash
systemctl stop c4ed
SNAP_RPC=https://c4e.rpc.m.stavr.tech:443
LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height); \
BLOCK_HEIGHT=$((LATEST_HEIGHT - 1000)); \
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

echo $LATEST_HEIGHT $BLOCK_HEIGHT $TRUST_HASH

sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC\"| ; \
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"| ; \
s|^(seeds[[:space:]]+=[[:space:]]+).*$|\1\"\"|" $HOME/.c4e-chain/config/config.toml
c4ed tendermint unsafe-reset-all --home /root/.c4e-chain
wget -O $HOME/.c4e-chain/config/addrbook.json "https://server-1.stavr.tech/Mainnet/C4e/addrbook.json"
sudo systemctl restart c4ed && journalctl -fu c4ed -o cat
```

## SnapShot Mainnet updated every 5 hours

{% hint style="success" %} <mark style="color:orange;">**You can check the size and time of snapshot creation with this command**</mark>\
`curl -sI https://server-1.stavr.tech/Mainnet/C4e/c4e-snap-1.tar.lz4 | grep "last" && curl -sI https://server-1.stavr.tech/Mainnet/C4e/c4e-snap-1.tar.lz4 | grep content-length | awk '{printf "%.2f GB\n", $2/1024/1024/1024}'`
{% endhint %}

```bash
cd $HOME
apt install lz4
sudo systemctl stop c4ed
cp $HOME/.c4e-chain/data/priv_validator_state.json $HOME/.c4e-chain/priv_validator_state.json.backup
rm -rf $HOME/.c4e-chain/data
LATEST_SNAPSHOT=$(curl -s https://server-1.stavr.tech/Mainnet/C4e/ | grep -oE 'c4e-snap-[0-9]+\.tar\.lz4' | while read SNAPSHOT; do HEIGHT=$(curl -s "https://server-1.stavr.tech/Mainnet/C4e/${SNAPSHOT%.tar.lz4}-info.txt" | awk '/Block height:/ {print $3}'); echo "$SNAPSHOT $HEIGHT"; done | sort -k2 -nr | head -n 1 | awk '{print $1}')
curl -o - -L https://server-1.stavr.tech/Mainnet/C4e/$LATEST_SNAPSHOT | lz4 -c -d - | tar -x -C $HOME/.c4e-chain
mv $HOME/.c4e-chain/priv_validator_state.json.backup $HOME/.c4e-chain/data/priv_validator_state.json
wget -O $HOME/.c4e-chain/config/addrbook.json "https://server-1.stavr.tech/Mainnet/C4e/addrbook.json"
sudo systemctl restart c4ed && journalctl -fu c4ed -o cat
```

### Start

```bash
sudo systemctl daemon-reload
sudo systemctl enable c4ed
sudo systemctl restart c4ed && sudo journalctl -fu c4ed -o cat
```

#### Create validator

```python
c4ed tx staking create-validator \
  --amount 1000000uc4e \
  --from <walletName> \
  --commission-max-change-rate "0.1" \
  --commission-max-rate "0.2" \
  --commission-rate "0.1" \
  --min-self-delegation "1" \
  --pubkey  $(c4ed tendermint show-validator) \
  --moniker STAVR_guide \
  --chain-id perun-1 \
  --identity="" \
  --details="" \
  --website="" -y
```

## [🧩Services and Tools🧩](https://stavr-team.gitbook.io/nodes-guides/mainnets/c4e/statesync-snapshot)

## Monitoring

You can set up your node status alarm here - [Monitoring](https://stavr-team.gitbook.io/nodes-guides/monitoring)

## Security

You can create secure management of your wallet and your node by following this links.

[TMKMS](https://stavr-team.gitbook.io/nodes-guides/tmkms)               [Wallet Security](https://stavr-team.gitbook.io/nodes-guides/wallet-security)

### Delete node

```bash
sudo systemctl stop c4ed
sudo systemctl disable c4ed
rm /etc/systemd/system/c4ed.service
sudo systemctl daemon-reload
cd $HOME
rm -rf c4e-chain
rm -rf .c4e-chain
rm -rf $(which c4ed)
```
