# Mainnet/Testnet: Running Nodes using AWS 1-click Deployment

This tutorial will use our AWS 1-click Deployment image to start and create the latest Cronos POS Chain 1-Click Node for both Mainnet and Testnet

{% hint style="warning" %}
**CAUTION** We do not recommend directly running validator on Mainnet by 1-Click deployment. Please use it with caution! Because the 1-click deployment is not running with [TMKMS](https://github.com/iqlusioninc/tmkms) and your tendermint validator key is in plain text `/chain/.chain-maind/config/priv_validator_key.json`. You may consider running validator with [tmkms on AWS nitro-enclave](https://docs.cronos-pos.org/for-node-hosts/advanced-tmkms-integration).
{% endhint %}

## Step 1. AWS Account Creation

You will first need to create an [AWS](https://aws.amazon.com/) account. This will require providing your credit card information to `AWS` and you may be subject to getting charged when you create a virtual machine. More details on account creation, check this [link](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/).

Please read `AWS` free trial [page](https://aws.amazon.com/free/?all-free-tier.sort-by=item.additionalFields.SortRank\&all-free-tier.sort-order=asc) to see if you are eligible for the free-tier.

## Step 2. Common Setup

### Step 2-0. Go to EC2 page and change the region

Sign in to your AWS account and go to EC2 Dashboard and change to your favourite region. Click "Launch Instance"

<figure><img src="https://2752961220-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2xcZ8Rr2cOSGVblWtVsF%2Fuploads%2Fgit-blob-4a72da622a6533b0a17bb5e9d079c1131842c0ea%2Faws_ec2_dashboard.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Step 2-1. Search for Cronos POS Chain 1-Click Node on AWS Marketplace

Search for "Cronos POS Chain 1-Click Node" in **Choose an Amazon Machine Image (AMI)** section. Select "Cronos POS Chain 1-Click Node" from the search results.&#x20;

<figure><img src="https://2752961220-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2xcZ8Rr2cOSGVblWtVsF%2Fuploads%2Fgit-blob-18d3ecfb4cf8d6ba53a7bd1e527b5528faf86833%2Faws_marketplace.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Step 2-2. Choose an instance type

By default, it will choose the recommended instance type (**m5a.large**) for you. But you can choose another instance type based on [Mainnet](https://docs.cronos-pos.org/for-node-hosts/getting-started/mainnet_validator#pre-requisites)/[Testnet](https://docs.cronos-pos.org/for-node-hosts/getting-started/croeseid-testnet) requirements.&#x20;

<figure><img src="https://2752961220-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2xcZ8Rr2cOSGVblWtVsF%2Fuploads%2Fgit-blob-0fda268b064375ff932b5f7aeb0364d03409910b%2Faws_instance.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Step 2-3. Configure instance details

![](https://2752961220-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2xcZ8Rr2cOSGVblWtVsF%2Fuploads%2Fgit-blob-52895ffdb73684044a9cb2cbfacd78a8dcff99d8%2Faws_config_instance.png?alt=media)

| Configuration           | Value                                                       |
| ----------------------- | ----------------------------------------------------------- |
| *Network*               | Select an existing one or default vpc if you don't have any |
| *Subnet*                | Choose a subnet or default subnet if you don't have any     |
| *Auto-assign Public IP* | Enable                                                      |
| *Other fields*          | Follow default setting                                      |

### Step 2-4. Add Storage

* Follow the default setting with `125` Throughput (MB/s)

### Step 2-5. Add Tags

* Create Tag if needed

### Step 2-6. Configure Security Group

By default, the image creates a new security group for you allowing ssh, p2p, rpc, and rest ports. You can remove the default opened rules or add more rules for example: grpc(9090), node\_exporter(9100), prometheus (26660), etc.

| Default Port                                                                                         | Description |
| ---------------------------------------------------------------------------------------------------- | ----------- |
| *22*                                                                                                 | ssh         |
| *26656*                                                                                              | p2p         |
| *26657*                                                                                              | rpc         |
| *1317*                                                                                               | rest        |
| You should consider updating your security group rules to allow access from known IP addresses only. |             |

### Step 2-7. Review Instance Launch

Click "Launch" once you finish the review

<figure><img src="https://2752961220-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F2xcZ8Rr2cOSGVblWtVsF%2Fuploads%2Fgit-blob-cdd433fb2ca791953767fdc39c61a58043e98cd5%2Faws_launch.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

You can either create a new key pair or import a key pair. Follow this [instruction](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html#prepare-key-pair).

### Step 2-8. Connect to your instance

Once the deployment is completed, you can connect to your instance via SSH.

```bash
$ ssh ubuntu@PUBLIC_IP -i YOUR_KEY.pem
```

AfterwardAfterwards, go to the `chain` directory, and you will find all the essential binaries for setting up your node:

```bash
$ cd /chain/
$ ll
total 32
drwxr-xr-x  7 crypto crypto 4096 Mar 20 14:51 ./
drwxr-xr-x 20 root   root   4096 Mar 25 09:46 ../
drwxr-xr-x  4 crypto crypto 4096 Mar 20 14:47 .chain-maind/
drwxr-xr-x  2 crypto crypto 4096 Mar 20 14:44 bin/
drwxr-xr-x  2   3434   3434 4096 Mar  5 09:41 node_exporter-1.1.2.linux-amd64/
-rwxr-xr-x  1 crypto crypto  535 Mar 20 14:43 reconfig.sh*
drwxr-xr-x  2 root   root   4096 Mar 20 14:43 release_binary/
drwxr-xr-x  2 crypto crypto 4096 Mar 20 14:47 sockets/
```

## Step 3. Running a full node

### Step 3-1. Use the reconfiguration script

Now we use the reconfiguration script `reconfig.sh` to choose the existing networks to join.

```bash
$ sudo -u crypto /chain/reconfig.sh
Please select either mainnet(M) or testnet(T) to join (M/T): M
You can select the following networks to join
	0. crypto-org-chain-mainnet-1
Please choose the network to join by index (0/1/...): 0
The selected network is crypto-org-chain-mainnet-1
The genesis does not exit or the sha256sum does not match the target one. Download the target genesis from github.
💾 Downloading crypto-org-chain-mainnet-1 genesis
```

(**Optional**) You may also enable [STATE-SYNC](https://docs.tendermint.com/v0.34/tendermint-core/state-sync.html). 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 validator. For **validator**, It will be amazingly fast to sync the near head of the chain and join the network.

{% hint style="warning" %}
**CAUTION** Blocks before state-sync `trust height` will **NOT** be queryable. If you want to run a **full node** or a validator with complete blockchain data; It is not suggested to use state-sync.
{% endhint %}

```bash
...
Do you want to enable state-sync? (Y/N): Y
State-sync require the latest version of binary to state-sync from the latest block.
The binary does not exist or the version does not match the target version. Download the target version binary from github release.
💾 Downloading crypto-org-chain-mainnet-1 binary
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   644  100   644    0     0   6192      0 --:--:-- --:--:-- --:--:--  6192
100 13.7M  100 13.7M    0     0  43.6M      0 --:--:-- --:--:-- --:--:-- 43.6M
```

Clean up the old blockchain data (if any)

```bash
...
Reset chain-maind and remove data if any
❗️ Enter (Y/N) to confirm to delete any old data: Y
Stopping chain-maind service
3:18PM INF Removed all blockchain history dir=/chain/.chain-maind/data
3:18PM INF Generated private validator file keyFile=/chain/.chain-maind/config/priv_validator_key.json stateFile=/chain/.chain-maind/data/priv_validator_state.json
❗️ /chain/.chain-maind/config/priv_validator_key.json already exists! Do you want to override old key? (Y/N): Y
A new priv_validator_key.json with pubkey: open /chain/.chain-maind/config/priv_validator_key.json: no such file or directory

💡 Please make sure you have a backup of /chain/.chain-maind/config/priv_validator_key.json in case of unexpected accidents!
```

The consensus public key information could be found in `/chain/.chain-maind/config/priv_validator_key.json`

Backup your old `/chain/.chain-maind/config/priv_validator_key.json` if you ever created.

```bash
❗️ /chain/.chain-maind/config/priv_validator_key.json already exists! Do you want to override old key? (Y/N): Y
A new priv_validator_key.json with pubkey: open /chain/.chain-maind/config/priv_validator_key.json: no such file or directory

💡 Please make sure you have a backup of /chain/.chain-maind/config/priv_validator_key.json in case of unexpected accidents!
```

The script will also ask you to fill in the `moniker` value which is a human-readable display name for tendermint p2p. *p2p gossip* will allow you to connect with more nodes (data sources).

```bash
Replace moniker in /chain/.chain-maind/config/config.toml
Moniker is display name for tendermint p2p

moniker: YOUR_MONIKER_NAME
Do you want to add the public IP of this node for p2p gossip? (Y/N): Y
✅ Added public IP to external_address in chain-maind config.toml for p2p gossip
```

*node\_id* and *node\_key* are the unique identity of your node. Save them for later use.

```bash
...
Generate and replace node_key in /chain/.chain-maind/config/node_key.json

You may want to save node_id and node_key for later use

node_id: 62cf74XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

node_key: LyQiGlL4HsdHsPXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
```

`chain-maind` is now running in the background as a systemd service.

You can check its log by the command `journalctl`, for example:

```bash
$ journalctl -u chain-maind.service -f
-- Logs begin at Wed 2020-12-30 13:51:25 UTC. --
Mar 25 15:34:02 ip-172-31-69-43 chain-maind[2657]: 3:34PM INF finalizing commit of block hash=3CB6E9CFAEB6681797E02547A096C9654A4558701660DCA78182CA1B43AA05F3 height=8460 module=consensus num_txs=3 root=39878A5AC834C6D89ADBC55097A6495FCE8C9E6FF8DE8DAAC5DD7373407A5C6D
Mar 25 15:34:02 ip-172-31-69-43 chain-maind[2657]: 3:34PM INF minted coins from module account amount=7925328957basecro from=mint module=x/bank
Mar 25 15:34:02 ip-172-31-69-43 chain-maind[2657]: 3:34PM INF executed block height=8460 module=state num_invalid_txs=0 num_valid_txs=3
Mar 25 15:34:02 ip-172-31-69-43 chain-maind[2657]: 3:34PM INF updates to validators module=state updates=A7E76081779FF5EE79A765DE4D716B4903D6902B:4266505417
Mar 25 15:34:02 ip-172-31-69-43 chain-maind[2657]: 3:34PM INF commit synced commit=436F6D6D697449447B5B36352032313020313636203639203130203633203137322032372031363120313438203133322031313320313031203135203131302031353720323134203134372034302034203234362032343220323237203231362032362031363220333120313431203231342032303020313239203234345D3A323130437D
Mar 25 15:34:02 ip-172-31-69-43 chain-maind[2657]: 3:34PM INF committed state app_hash=41D2A6450A3FAC1BA1948471650F6E9DD6932804F6F2E3D81AA21F8DD6C881F4 height=8460 module=state num_txs=3
...
```

The consensus public key can be found by and please take note of it for the next [steps](https://docs.cronos-pos.org/for-node-hosts/getting-started/aws-1click#step-4.-join-as-a-validator):

```
$ sudo /chain/bin/chain-maind tendermint show-validator --home /chain/.chain-maind/
## [crocnclcons... address] ##
## [tcrocnclcons... address] ##
```

The latest block height can be found by:

Mainnet

```bash
$ curl -s https://rpc.mainnet.crypto.org:443/block | jq -r .result.block.header.height
8525
```

Testnet

```bash
$ curl -s https://testnet-croeseid-4.crypto.org:26657/block | jq -r .result.block.header.height
8525
```

Once the tendermint syncs to the latest block, the setup is done! You may move on to the next step if you want to join the network as a validator.

## Step 4. Join as a validator

We suggest that you should do this process locally with `chain-maind` to avoid exposing your keys on a cloud server. If you haven't installed `chain-maind` yet, please follow [Step 1. Get the Cronos POS Chain binary for testnet](https://docs.cronos-pos.org/for-node-hosts/getting-started/croeseid-testnet) or [Step 1. Get the Cronos POS Chain Mainnet binary for mainnet](https://docs.cronos-pos.org/for-node-hosts/getting-started/mainnet).&#x20;

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

* Check whether your chain-maind is mainnet or testnet binary

Mainnet

```bash
$ chain-maind version
3.3.9
```

* Mainnet binary for [Mac](https://github.com/crypto-org-chain/chain-main/releases/download/v3.3.9/chain-main_3.3.9_Darwin_x86_64.tar.gz) and [Windows](https://github.com/crypto-org-chain/chain-main/releases/download/v3.3.9/chain-main_3.3.9_Windows_x86_64.zip) are also available.

Or

Testnet

```bash
$ chain-maind version
3.1.0-croeseid
```

* Testnet 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.
  {% endhint %}

<details>

<summary><strong>Mainnet</strong></summary>

### Create a new key and address

Please follow [Step 3-1. Create a new key and address](https://docs.cronos-pos.org/for-users/wallets/cli#keys-management-chain-maind-keys)

### Creating a validator node

You should obtain a consensus public key from [Step 3-1. Use the reconfiguration script](https://docs.cronos-pos.org/~/changes/2e2355w5GSNes3nTqLmc/for-node-hosts/getting-started/aws-1click?r=4ufDBgXrbDIE7JCAgzaq#step-3-1.-use-the-reconfiguration-script)

Please follow Step 3-5. [Joining the network as a validator to create a validator](https://docs.cronos-pos.org/for-node-hosts/getting-started/mainnet).

### Check if the validator has been set

Back your server, and follow [Step 3-6. Check your validator status](https://docs.cronos-pos.org/for-node-hosts/getting-started/mainnet_validator#step-3-3.-check-your-validator-status)

🎊 Congratulations! You've successfully joined the network as a validator! 🎊

</details>

<details>

<summary><strong>Testnet</strong></summary>

### Create a new key and address

Please follow [Step 3-1. Create a new key and address](https://docs.cronos-pos.org/for-node-hosts/getting-started/croeseid-testnet#step-3-1.-create-a-new-key-and-address)

### Creating a validator node

You should obtain a consensus public key from [Step 3-1. Use the reconfiguration script](https://docs.cronos-pos.org/for-node-hosts/getting-started/azure-1click#step-3-1.-use-the-reconfiguration-script)

Please follow [Step 3-2 Joining the network as a validator to create a validator](https://docs.cronos-pos.org/for-node-hosts/getting-started/mainnet_validator#step-3-2.-joining-the-network-as-a-validator-send-a-create-validator-transaction).

### Check if the validator has been set

Back your server, and follow [Step 3-6. Check your validator status](https://docs.cronos-pos.org/for-node-hosts/getting-started/mainnet_validator#step-3-3.-check-your-validator-status)

🎊 Congratulations! You've successfully joined the network as a validator! 🎊

</details>
