# Setup Blockchain
## Prerequisites
- Install golang, version 1.13+
- For Ubuntu: [link](https://medium.com/better-programming/install-go-1-11-on-ubuntu-18-04-16-04-lts-8c098c503c5f).
*Change the version to latest by editing go1.11.linux-amd64.tar.gz to go1.1x.x.linux-amd64.tar.gz*
- For Windows: [link](https://www.youtube.com/watch?v=f1rZ47Gj7x4)
**Note:** In Windows, you need to install GCC also. Go to [this link](http://www.codebind.com/cprogramming/install-mingw-windows-10-gcc/).
- Download persistenceSDK:
`git clone -v https://github.com/persistenceOne/persistenceSDK.git`
- Go to persistenceSDK directory.
`cd persistenceSDK`
- Switch to `version0.1` branch:
`git checkout version0.1`
- Install commit blockchain:
- Ubuntu: `make all`
- Windows: Run `make.bat`
- Verify:
- In `terminal`/`cmd`, type `maind version` and `maincli version`, you should get a proper response
## Setting up genesis:
- Initialize Node
`maind init [moniker] --chain-id [chainID]`
**Note:**
- `moniker` will be the name of your node
- `chainID` is name of the chain you want to set up
- Create genesis account
`maincli keys add [key_name]`
**Note:**
- Add flag `--recover` in the above to give mnemonic manually.
- `[key_name]` is the username of the account
- Add tokens to the genesis account
`maind add-genesis-account [genesis_account_key_name] [coins_to_account]`
**Note:** `[coins]` in the format: `10000000000000000000ucommit`
## Setting up Validator node:
- Initialize Node
`maind init [moniker]`
- Replace your `genesis.json` file in `.maind/config/` directory with the one from the genesis node
- In Windows, `.maind` folder is in `C:`
- In Ubuntu, it's located in `home` directory as a hidden folder
- Create your account
`maincli keys add [key_name]`
- **To become validator at genesis:**
- Add tokens to your account:
`maind add-genesis-account [genesis_account_key_name] [coins_to_account]`
- Create your genesis transaction (this is staking):
`maind gentx --name [key_name] --amount [coins_to_stake]`
- Collect your genesis transaction:
`maind collect-gentxs`
- Send the contents of `.maind/config/gentx/gentx-[node_id].json` file and `[coins_to_account]` amount to genesis.
- Genesis needs to add the gensis transaction received from the node to its `genesis.json` file in `gentxs` field and also create an account for the validator node in the field `accounts` in the same format given there for genesis's own account. Change the amount of coins for the validator accounts as per `[coins_to_account]` amount received.
- The genesis then needs to send the it's updated `genesis.json` to all the validators who are being created at genesis. And the validators needs to update their `genesis.json` with the new file.
- **To become validator during runtime:**
- Give values of node id and it's ip_address:port you want to connect to in the format `node_id@ip_address:port` in `seeds` or `persistent_peers` in `.maind/config/config.toml`
- Start the chain `maind start`
- Get some coins in your account
- Stake your coins:
`maincli tx staking create-validator --from [key_name] --min-self-delegation 1 --commission-max-change-rate 0.1 --commission-max-rate 0.1 --commission-rate 0.1 --moniker [moniker_name] --amount [coins_to_stake] --pubkey [validator_consensus_pubkey] --chain-id [chainID]`
**Note:** `validator_consensus_pubkey` can be found by command:
`maind tendermint show-validator`
**Note:** For any other details or help type:
`maincli tx staking create-validator -h`
- The validator then needs to add `node_id@ip_address:port` in `seeds` or `persistent_peers` in `.maind/config/config.toml` of genesis and all the other nodes (of any kind) it wants to connect to.
- Example:
`seeds = "50f3fb09270bfaabcdb6e802279e24d3342b9794@172.31.30.160:26656, 8abfe552a9f210584f2096a8bfe34e812079f653@172.31.24.22:26656, c7fd3c3775a07ce0b235ee27d805da3f98c1b3db@172.31.27.25:26656"`
**Note:** Ifyou add only `persistent_peers`, blockchain will never start until it has set up connections with at least one of the persistent peers.
**Note:** `nodeID` can found by `maind tendermint show-node-id`
- Start the chain
`maind start`
- Start the light client
`maincli rest-server --chain-id=[chain_name] --node=tcp://0.0.0.0:26657 --laddr=tcp://0.0.0.0:31118`
**Note:** Change `31118` to run light client on any other port.
- **To Edit Validator:**
`maincli tx staking edit-validator --from [validator_key_name] --identity="[identity_Signature]" --moniker="[validator_moniker_name]" --details="[details]" --website="[URL]" --chain-id [chain_name]`
## Setting up Sync node:
- Initialize Node
`maind init [moniker]`
- Replace your `genesis.json` file in `.maind/config/` directory with the one from the genesis node
- Give values of node id and it's ip_address:port you want to connect to in the format `node_id@ip_address:port` in `seeds` or `persistent_peers` in `.maind/config/config.toml`
- Start the chain
`maind start`
- Start the light client
`maincli rest-server --chain-id=[chain_name] --node=tcp://0.0.0.0:26657 --laddr=tcp://0.0.0.0:31118`
**Note:** Change `31118` to run light client on any other port.
## Setting up Sentry Nodes:
- Setup your validator node with following configurations:
- `pex: false`
- `persistent_peers: list of sentry nodes`
- `private_peer_ids: omitted`
- `addr_book_strict: false`
- Setup a sync node and configure it to the following to make it a sentry node:
- `pex: true`
- `persistent_peers: validator node, optionally other sentry nodes`
- `private_peer_ids: validator node id`
- `addr_book_strict: false`
**Note:** To change configuration, edit your `config.toml` file.
## Unjailing:
`maincli tx slashing unjail --from [key or address] --chain-id [chainID]`
## Staking:
- Delegate Coins:
- `/staking/delegators/commit1jqusu33shmadmgegs0rxqug24pc72079x5sypz/delegations`
```
{
"base_req": {
"from":"commit1jqusu33shmadmgegs0rxqug24pc72079x5sypz",
"chain_id":"crust-2"
},
"delegator_address": "commit1jqusu33shmadmgegs0rxqug24pc72079x5sypz",
"validator_address":"commitvaloper1jqusu33shmadmgegs0rxqug24pc72079p4clfe",
"amount": {
"denom": "ucommit",
"amount": "1000"
},
"password": "1234567890",
"mode": "block"
}
```
- Undelegate Coins:
- `/staking/delegators/commit1jqusu33shmadmgegs0rxqug24pc72079x5sypz/unbonding_delegations`
```
{
"base_req": {
"from":"commit1jqusu33shmadmgegs0rxqug24pc72079x5sypz",
"chain_id":"crust-2"
},
"delegator_address": "commit1jqusu33shmadmgegs0rxqug24pc72079x5sypz",
"validator_address":"commitvaloper1jqusu33shmadmgegs0rxqug24pc72079p4clfe",
"amount": {
"denom": "ucommit",
"amount": "1000"
},
"password": "1234567890",
"mode": "block"
}
```
- Redelgate Coins:
- `/staking/delegators/commit1jqusu33shmadmgegs0rxqug24pc72079x5sypz/redelegations`
```
{
"base_req": {
"from":"commit1jqusu33shmadmgegs0rxqug24pc72079x5sypz",
"chain_id":"crust-2"
},
"delegator_address": "commit1jqusu33shmadmgegs0rxqug24pc72079x5sypz",
"validator_src_address":"commitvaloper1jqusu33shmadmgegs0rxqug24pc72079p4clfe",
"validator_dst_address":"commitvaloper1jqusu33shmadmgegs0rxqug24pc72079p4clfe",
"amount": {
"denom": "ucommit",
"amount": "1000"
},
"password": "1234567890",
"mode": "block"
}
```