# Croeseid Testnet: Running Nodes

The latest Cronos POS Chain Testnet has been named as **Croeseid**.

This is detailed documentation for setting up a Validator or a full node on Croeseid testnet `testnet-croeseid-4`.

## Pre-requisites

### Supported OS

We officially support macOS, Windows and Linux only. Other platforms may work but there is no guarantee. We will extend our support to other platforms after we have stabilized our current architecture.

### Prepare your machine

To run Cronos POS Chain nodes in the testnet, you will need a machine with the following minimum requirements to run different types of nodes:

Archive Node (setting pruning = nothing)

* RAM: 16GB (goleveldb)
* Disk: 900GB
* CPU: 4 cores

Default Full Node (setting pruning = default)

* RAM 16GB (goleveldb)
* Disk: 150GB (Depends on how long the node is running for)
* CPU: 4 cores

## Step 0: Notes on network upgrades

For those that would like to build a **Run a Full Node with complete blockchain data** from scratch, note that there were several breaking network upgrades, requiring upgrading at designated block heights below:

| Block height    | Binary Version              | Instruction                                                                       |
| --------------- | --------------------------- | --------------------------------------------------------------------------------- |
| `1 - 8,302,700` | `chain-main_3.1.0-croeseid` | Start with this version.                                                          |
| `>`8,302,700    | `chain-main_4.2.2-croeseid` | When it reaches the target block height `8,302,700` update the binary and restart |

IMPORTANT: If you are not able to perform this upgrades, you can also request a testnet archive snapshot from us

## Step 1. Get the Cronos POS Chain testnet binary

{% hint style="info" %}
**Remarks**: The following is the minimal setup for a **validator node**.
{% endhint %}

{% hint style="info" %}
**Reminder**: The binary for *testnet* and the binary for *mainnet* are two **different** binaries. Please make sure you are using the correct binary.
{% endhint %}

To simplify the following step, we will be using **Linux** (Intel x86) for illustration. Binary for **Mac** ([Intel x86](https://github.com/crypto-org-chain/chain-main/releases/download/v3.1.0-croeseid/chain-main_3.1.0-croeseid_Darwin_x86_64.tar.gz) / [M1](https://github.com/crypto-org-chain/chain-main/releases/download/v3.1.0-croeseid/chain-main_3.1.0-croeseid_Darwin_arm64.tar.gz)) and [Windows](https://github.com/crypto-org-chain/chain-main/releases/download/v3.1.0-croeseid/chain-main_3.1.0-croeseid_Windows_x86_64.zip) are also available.

* To install Cronos POS Chain released **testnet binaries** from GitHub:

  ```bash
  $ curl -LOJ https://github.com/crypto-org-chain/chain-main/releases/download/v3.1.0-croeseid/chain-main_3.1.0-croeseid_Linux_x86_64.tar.gz
  $ tar -zxvf chain-main_3.1.0-croeseid_Linux_x86_64.tar.gz
  ```
* You can verify the installation by checking the version of the chain-maind, the current version is `3.1.0-croeseid.`

{% hint style="info" %}
**Reminder**: For macOS users: the binary is not signed, you have to follow the steps [here](https://support.apple.com/en-hk/guide/mac-help/mh40616/mac) to make the binary runnable.

```
$./chain-maind version
3.1.0-croeseid
```

{% endhint %}

## Step 2. Configure `chain-maind`

Before kick-starting your node, we will have to configure your node so that it connects to the Croeseid testnet:

### Step 2-0 (Optional) Clean up the old blockchain data

* If you have joined `testnet-croeseid-3` before, you would have to clean up the old blockchain data and start over again, it can be done by running:

  ```bash
  $ ./chain-maind unsafe-reset-all
  ```

  and remove the old Genesis file by

  ```
  $ rm ~/.chain-maind/config/genesis.json
  ```
* You can not override the previous validator through `chain-maind init`. If you want to have a new validator, you need to manually remove the `priv_validator_key.json`:

  ```bash
  rm ~/.chain-maind/config/priv_validator_key.json
  ```

  Then, in Step 2-1, `chain-maind init` should help you to generate a new validator key file.

### Step 2-1 Initialize `chain-maind`

* First of all, you can initialize chain-maind by:

  ```bash
    $ ./chain-maind init [moniker] --chain-id testnet-croeseid-4
  ```

  This `moniker` will be the displayed ID of your node when connected to Cronos POS Chain network. When providing the moniker value, make sure you drop the square brackets since they are not needed. The example below shows how to initialize a node named `pegasus-node` :

  ```bash
    $ ./chain-maind init pegasus-node --chain-id testnet-croeseid-4
  ```

  <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>NOTE</strong></p><ul><li>Depending on your chain-maind home setting, the chain-maind configuration will be initialized to that home directory. To simply the following steps, we will use the default chain-maind home directory <code>~/.chain-maind/</code> for illustration.</li><li>You can also put the <code>chain-maind</code> to your binary path and run it by <code>chain-maind</code></li></ul></div>

### Step 2-2 Configure chain-maind

* Download and replace the Croeseid Testnet `genesis.json` by:

  ```bash
  $ curl https://raw.githubusercontent.com/crypto-com/testnets/main/testnet-croeseid-4/genesis.json > ~/.chain-maind/config/genesis.json
  ```
* Verify sha256sum checksum of the downloaded `genesis.json`. You should see `OK!` if the sha256sum checksum matches.

  ```bash
  $ if [[ $(sha256sum ~/.chain-maind/config/genesis.json | awk '{print $1}') = "cf20fb923be3bc565e49a57e81a47ca969e8a973be7b3ed44e2734e369118b6c" ]]; then echo "OK"; else echo "MISMATCHED"; fi;

  OK!
  ```

  <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>NOTE</strong></p><ul><li><p>For Mac environment, <code>sha256sum</code> was not installed by default. In this case, you may setup <code>sha256sum</code> with this command:</p><pre class="language-bash"><code class="lang-bash">function sha256sum() { shasum -a 256 "$@" ; } &#x26;&#x26; export -f sha256sum
  </code></pre></li></ul></div>
* In `~/.chain-maind/config/app.toml`, update minimum gas price to avoid [transaction spamming](https://github.com/cosmos/cosmos-sdk/issues/4527)

  ```bash
  $ sed -i.bak -E 's#^(minimum-gas-prices[[:space:]]+=[[:space:]]+)""$#\1"0.025basetcro"#' ~/.chain-maind/config/app.toml
  ```
* For network configuration, in `~/.chain-maind/config/config.toml`, please modify the configurations of `persistent_peers`, `create_empty_blocks_interval` and `timeout_commit` by:

  ```bash
  $ sed -i.bak -E 's#^(persistent_peers[[:space:]]+=[[:space:]]+).*$#\1"71d2a4727bf574d5d368c343e37edff00cd556b1@seed-0.testnet-croeseid-4.cronos-pos.org:26656,8af7c92277f3edce58aa828cf1026cfa74fd6569@seed-1.testnet-croeseid-4.cronos-pos.org:26656"#' ~/.chain-maind/config/config.toml
  $ sed -i.bak -E 's#^(create_empty_blocks_interval[[:space:]]+=[[:space:]]+).*$#\1"5s"#' ~/.chain-maind/config/config.toml
  $ sed -i.bak -E 's#^(timeout_commit[[:space:]]+=[[:space:]]+).*$#\1"2s"#' ~/.chain-main
  ```

**Note**: We suggest using `persistent_peers` instead of `seeds` for a stable state-sync experience.

### Step 2-3 Enable STATE-SYNC

[STATE-SYNC](https://docs.tendermint.com/v0.34/tendermint-core/state-sync.html) is supported in our testnet! 🎉

With state sync your node will download data related to the head or near the head of the chain and verify the data. This leads to drastically shorter times for joining a network for validators.

However, you should keep in mind that the block before state-sync `trust height` will not be queryable. So if you want to run a full node, better not use state-sync feature to ensure your node has every data on the blockchain network.

For **validator**, it will be amazingly fast to sync the near head of the chain and join the network.

Follow the below optional steps to enable state-sync.

* For state-sync configuration, in `~/.chain-maind/config/config.toml`, please modify the configurations of \[statesync] `enable`, `rpc_servers`, `trust_height` and `trust_hash` by:

  ```bash

  $ LATEST_HEIGHT=$(curl -s https://testnet-croeseid-4.crypto.org:26657/block | jq -r .result.block.header.height); \
  BLOCK_HEIGHT=$((LATEST_HEIGHT - 1000)); \
  TRUST_HASH=$(curl -s "https://testnet-croeseid-4.crypto.org:26657/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)

  $ sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
  s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"https://testnet-croeseid-4.crypto.org:26657,https://testnet-croeseid-4.crypto.org:26657\"| ; \
  s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
  s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"| ; \
  s|^(seeds[[:space:]]+=[[:space:]]+).*$|\1\"\"|" ~/.chain-maind/config/config.toml
  ```

  <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>NOTE</strong></p><ul><li>For Mac environment, if <code>jq</code> is missing, you may install it by: <code>brew install jq</code></li></ul></div>

## Step 3. Run everything

{% hint style="warning" %}
**CAUTION**&#x20;

This page only shows the minimal setup for a validator node.

Furthermore, you may want to run full nodes as sentries (see [Tendermint](https://docs.tendermint.com/master/tendermint-core/running-in-production.html)), restrict your validator connections to only connect to your full nodes, test secure storage of validator keys etc.
{% endhint %}

### Step 3-1. Create a new key and address

Run the following to create a new key. For example, you can create a key with the name `Default` by:

```bash
  $ ./chain-maind keys add Default
```

You should obtain an address with `tcro` prefix, e.g. `tcro1quw5r22pxy8znjtdkgqc65atrm3x5hg6vycm5n`. This will be the address for performing transactions.

### Step 3-2. Obtain test token

Unless you have obtained the CRO testnet token before, use the [tcro faucet](https://crypto.org/faucet) to obtain test CRO tokens. In case you have reached the daily limit on faucet airdrop, you can simply send a message on [Discord](https://discord.gg/pahqHz26q4) #request-tcro channel, stating who you are and your `tcro.....` address.

### Step 3-3. Obtain the validator public key

You can obtain your validator public key by:

```bash
  $ ./chain-maind tendermint show-validator
```

be The public key should in a json format, for example:

```bash
{
  "@type": "/cosmos.crypto.ed25519.PubKey",
  "key": "[The_validator_key]"
}
```

### Step 3-4. Run everything

Once the `chain-maind` has been configured, we are ready to start the node and sync the blockchain data:

* Start chain-maind, e.g.:

```bash
  $ ./chain-maind start
```

{% hint style="info" %}
**Remarks**: If you see errors saying `too many files opened...`, then you need to set a higher number for maximum open file descriptors in your OS.

If you are on OSX or Linux, then the following could be useful:

```bash
# Check current max fd
$ ulimit -n
# Set a new max fd
$ ulimit -Sn [NEW_MAX_FILE_DESCRIPTOR]
# Example
$ ulimit -Sn 4096 
```

{% endhint %}

* *(Optional for Linux)* Start chain-maind with systemd service, e.g.:

```bash
  $ git clone https://github.com/crypto-org-chain/chain-main.git && cd chain-main
  $ ./networks/create-service.sh
  $ sudo systemctl start chain-maind
  # view log
  $ journalctl -u chain-maind -f
```

{% hint style="info" %}
**Example**: /etc/systemd/system/chain-maind.service created by script

```
# /etc/systemd/system/chain-maind.service
[Unit]
Description=Chain-maind
ConditionPathExists=/usr/local/bin/chain-maind
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/usr/local/bin
ExecStart=/usr/local/bin/chain-maind start --home /home/ubuntu/.chain-maind
Restart=on-failure
RestartSec=10
LimitNOFILE=50000

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

{% endhint %}

It should begin fetching blocks from the other peers. Please wait until it is fully synced before moving onto the next step.

* You can query the node syncing status by

  ```bash
  $ ./chain-maind status 2>&1 | jq '.SyncInfo.catching_up'
  ```

  If the above command returns `false`, It means that your node **is fully synced**; otherwise, it returns `true` and implies your node is still catching up.
* One can check the current block height by querying the public full node by:

  ```bash
  curl -s https://testnet-croeseid-4.crypto.org:26657/commit | jq "{height: .result.signed_header.header.height}"
  ```

  and you can check your node's progress (in terms of block height) by

  ```bash
  $ ./chain-maind status 2>&1 | jq '.SyncInfo.latest_block_height'
  ```

### Step 3-5. Send a `create-validator` transaction

Once the node is fully synced, we are now ready to send a `create-validator` transaction and join the network, for example:

```
$ ./chain-maind tx staking create-validator \
--from=[name_of_your_key] \
--amount=500000tcro \
--pubkey='{"@type":"/cosmos.crypto.ed25519.PubKey","key":"PUBLIC_KEY"}'  \
--security-contact="[security contact email/contact method]" \
--chain-id="testnet-croeseid-4" \
--commission-rate="0.10" \
--commission-max-rate="0.20" \
--commission-max-change-rate="0.01" \
--min-self-delegation="1" \
--gas 80000000 \
--gas-prices 0.1basetcro

{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgCreateValidator"...}
confirm transaction before signing and broadcasting [y/N]: y
```

You will be required to insert the following:

* `--from`: The `trco...` address that holds your funds;
* `--pubkey`: The validator public key( See Step [3-3](#step-3-3-obtain-the-validator-public-key) above );
* `--moniker`: A moniker (name) for your validator node;
* `--security-contact`: Security contact email/contact method.

### Step 3-6. Check your validator status

Once the `create-validator` transaction completes, you can check if your validator has been added to the validator set:

```bash
$ ./chain-maind tendermint show-address
## [tcrocnclcons... address] ##
$ ./chain-maind query tendermint-validator-set | grep -c [tcrocnclcons...]
## 1 = Yes; 0 = Not yet added ##
```

To further check if the validator is signing blocks, kindly run this [script](https://github.com/crypto-com/chain-docs/blob/master/docs/getting-started/assets/signature_checking/check-validator-up.sh), for example:

```bash
$ curl -sSL https://raw.githubusercontent.com/crypto-com/chain-docs/master/docs/getting-started/assets/signature_checking/check-validator-up.sh | bash -s -- \
--tendermint-url https://testnet-croeseid-4.crypto.org:26657 \
--pubkey $(cat ~/.chain-maind/config/priv_validator_key.json | jq -r '.pub_key.value')

The validator is in the active validator set under the address  <YOUR_VALIDATOR_ADDRESS>
The validator is signing @ Block#<BLOCK_HEIGHT> 👍
```

```bash
$ curl -sSL https://raw.githubusercontent.com/crypto-com/chain-docs/master/docs/getting-started/assets/signature_checking/check-validator-up.sh | bash -s -- \
--tendermint-url https://testnet-croeseid-4.crypto.org:26657 \
--bechpubkey [tcrocnclconspub1....]

The validator is in the active validator set under the address  <YOUR_VALIDATOR_ADDRESS>
The validator is signing @ Block#<BLOCK_HEIGHT> 👍
```

Alternatively, you can run it on this [browser based IDE](https://repl.it/@allthatjazzleo/cryptocomcheckNodeJoinStatus#main.go), by specifying your validator public key in the `"YOUR_PUBKEY"` field, where this key can be obtained by running

```bash
$ cat ~/.chain-maind/config/priv_validator_key.json | jq -r '.pub_key.value'
```

## Step 4. Perform Transactions

### Step 4-1. `query bank balances` - Check your transferable balance

You can check your *transferable* balance with the `balances` command under the bank module.&#x20;

{% hint style="info" %}
**Example**: Check your address balance

```bash
$ ./chain-maind query bank balances tcro1quw5r22pxy8znjtdkgqc65atrm3x5hg6vycm5n

balances:
- amount: "10005471622381693"
  denom: basetcro
pagination:
  next_key: null
  total: "0"

```

{% endhint %}

### Step 4-2. `tx bank send` - Transfer operation

Transfer operation involves the transfer of tokens between two addresses.

#### **Send Funds** \[`tx bank send <from_key_or_address> <to_address> <amount> <network_id>`]

{% hint style="info" %}
**Example**: Send 10tcro from one address to another.

```bash
$ ./chain-maind tx bank send Default tcro1j7pej8kplem4wt50p4hfvndhuw5jprxxn5625q 10tcro --chain-id "testnet-croeseid-4" --gas-prices 0.1basetcro
  ## Transaction payload##
  {"body":{"messages":[{"@type":"/cosmos.bank.v1beta1.MsgSend","from_address"....}
confirm transaction before signing and broadcasting [y/N]: y
```

{% endhint %}

### Step 4-3. `tx staking` - Staking operations

{% hint style="info" %}
**NOTE**

* To get the 'validator-addr' with bech32 prefix, you can run this command:

  ```bash
  ./chain-maind keys show Default --bech val
  ```

{% endhint %}

Staking operations involve the interaction between an address and a validator. It allows you to create a validator and lock/unlocking funds for staking purposes.

#### **Delegate your funds to a validator** \[`tx staking delegate <validator-addr> <amount>`]

To bond funds for staking, you can delegate funds to a validator by the `delegate` command

{% hint style="info" %}
**Example**: Delegate funds from `Default` to a validator under the address `tcrocncl16k...edcer`
{% endhint %}

```bash
$ ./chain-maind tx staking delegate tcrocncl16kqr009ptgken6qsxnzfnyjfsq6q97g3uedcer 100tcro --from Default --chain-id "testnet-croeseid-4" --gas-prices 0.1basetcro
## Transactions payload##
{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgDelegate"....}
confirm transaction before signing and broadcasting [y/N]: y
```

#### **Unbond your delegated funds** \[`tx staking unbond <validator-addr> <amount>`]

On the other hand, we can create a `Unbond` transaction to unbond the delegated funds

**Example**: Unbond funds from a validator under the address `tcrocncl16k...edcer`

```bash
$ ./chain-maind tx staking unbond tcrocncl16kqr009ptgken6qsxnzfnyjfsq6q97g3uedcer 100tcro --from Default --chain-id "testnet-croeseid-4" --gas-prices 0.1basetcro
## Transaction payload##
{"body":{"messages":[{"@type":"/cosmos.staking.v1beta1.MsgUndelegate"...}
confirm transaction before signing and broadcasting [y/N]: y
```

{% hint style="info" %}
Once your funds are unbonded, they will be locked until the `unbonding_time` has passed.
{% endhint %}

### Reward related transactions and queries

After you have delegated or created a validator, the reward will be accumulated, you can check/ withdraw it by:

#### `query distribution validator-outstanding-rewards` - Query un-withdrawn rewards for a validator

We can check the distribution outstanding (un-withdrawn) rewards for a validator and all of their delegations by operator address.

{% hint style="info" %}
**Example**: Check all outstanding rewards under the operator address `tcrocncl1...zrf8`

```bash
$ ./chain-maind q distribution validator-outstanding-rewards tcrocncl1kkqxv3szgh099xezt7y38t5anqzue4s326zrf8
  rewards:
  - amount: "1920761912.927067330419141688"
    denom: basetcro
```

{% endhint %}

#### `tx distribution validator-outstanding-rewards` - Query un-withdrawn rewards for a validator

We can check distribution outstanding (un-withdrawn) rewards for a validator and all of their delegations by their operator address.

{% hint style="info" %}
**Example**: Withdraw all outstanding under a delegation address:

```bash
$ ./chain-maind tx distribution withdraw-all-rewards --from [key_name] --chain-id "testnet-croeseid-4" --gas-prices 0.1basetcro

{"body":{"messages":[{"@type":"/cosmos.distribution.v1beta1.MsgWithdrawDelegatorReward"...}]}
confirm transaction before signing and broadcasting [y/N]: y
```

{% endhint %}

### Slashing related transaction

### `tx slashing unjail` - Unjail a validator

Validator could be punished and jailed due to network misbehaviour, we can check the jailing status of a validator, for example:

```bash
$ ./chain-maind query staking validators -o json | jq
................................
      "operator_address": "tcrocncl1hct8ye56gk80qjxvrx299yu9v98aqaxe0y5kvg",
      "consensus_pubkey": {
        "@type": "/cosmos.crypto.ed25519.PubKey",
        "key": "P1/aHuScW5myVs+xH10R8yFT2u0wwaCKXfDKSuVTl60="
      },
      "jailed": true,
................................
```

Where `"jailed": true` implies that the validator has been jailed. After the jailing period has passed, one can broadcast a `unjail` transaction to unjail the validator and resume its normal operations by

```bash
$ ./chain-maind tx slashing unjail --from [key_name] --chain-id "testnet-croeseid-4" --gas-prices 0.1basetcro

  {"body":{"messages":[{"@type":"/cosmos.slashing.v1beta1.MsgUnjail"...}]}
  confirm transaction before signing and broadcasting [y/N]: y
```

Congratulations! You've successfully set up a Testnet node and performed some basic transactions! You may refer to [Wallet Management](https://docs.cronos-pos.org/for-users/wallets/cli#transactions-subcommands-chain-maind-tx) for more advanced operations and transactions.

## Croeseid testnet faucet and explorer

* You can lookup data within the `testnet-croeseid-4` network by the [explorer](https://crypto.org/explorer/croeseid4/);
* To interact with the blockchain, simply use the [test-token faucet](https://crypto.org/faucet) to obtain test CRO tokens for performing transactions on the **Croeseid** testnet.
  * Note that you will need to create an [address](https://docs.cronos-pos.org/for-node-hosts/getting-started/croeseid-testnet#step-3-1.-create-a-new-key-and-address) before using the faucet.
