# Run multiple XSAT Validators

If your company plans to operate multiple XSAT Validator nodes, follow this structured approach to streamline the process:

### Roles Within the Company

* **Operations Team**: Handles the initialization of XSAT Validator accounts and manages node operations.
* **Finance Team**: Manages XSAT (for staking) and BTC (for gas fees) and oversees the collection of XSAT rewards.

### Assumptions

1. You aim to run 10 nodes named `sat1`, `sat2`, `sat3`, ..., `sata` on a single server.

### Preparations Before Operation

#### **1. Server Setup**

For running 10 XSAT Validator nodes, the recommended server configuration is:

* **CPU**: 2 cores
* **RAM**: 8 GB
* **Disk**: 40 GB

Ensure that all necessary [software ](https://docs.exsat.network/guides-of-data-consensus/others/operation-references/preparation-before-you-start/prerequisites)is installed on the server.

#### **2. Account Setup**

The finance team should prepare the following accounts:

* **Stake Account**:
  * Should hold at least **21,000 XSAT** (2,100 XSAT per validator) for staking.
  * Should hold sufficient BTC to cover gas fees (approximately **0.0005 BTC** per validator per month according to current gas fee level).
  * **The private key for this EVM account is retained exclusively by the finance team**.
* **Temporary Account**:
  * Used specifically to pay network resource fees for creating XSAT Validator accounts.
  * Each XSAT Validator account requires **0.000102 BTC** (0.0001 BTC for creating the exSat Validator account and 0.000002 BTC for gas fee) for creation. For 10 validators, prepare at least **0.00102 BTC**.
  * **The private key for this account should be shared with the operations team to facilitate account creation**.

**3. BTC Node Setup**

A BTC node is required to provide BTC RPC services. Both full nodes and light nodes are supported. Follow [this ](https://docs.exsat.network/guides-of-data-consensus/others/operation-references/preparation-before-you-start/run-a-btc-node)to set up a BTC node.

### Batch Operation Steps

#### 1. Initialize the XSAT Validator Accounts

**Clone the Repository and Configure the `.env` File**

```
git clone https://github.com/exsat-network/batch-reg-xsat-validators
cd batch-reg-xsat-validators
cp .env.example .env
vim .env
```

**Configure the `.env` File**

Below is an example `.env` file. Update the values as needed. By default, it is configured for the mainnet, but you can modify it for the Hayek testnet if required.

```
# Network name | testnet
NETWORK=mainnet

# exsat node |testnet https://chain-tst3.exactsat.io
EXSAT_RPC_URLS=["https://rpc-us.exsat.network"]

# exsat-evm node and chainId | testnet https://evm-tst3.exsat.network
EVM_RPC_URL=https://evm.exsat.network

# exsat-evm node and chainId | testnet 839999
EVM_CHAIN_ID=7200

# Private key of the Tempory account - starts with 0x,needs sufficient BTC for creating exSat Validator accounts (e.g., 10*0.0001 BTC for 10 exSat Validators)
PRIVATE_KEY=0x00000000000

# Stake Address, needs sufficient $XSAT for staking & $BTC for refilling gas fees, starts with 0x
# Only Address is needed
STAKER_REWARD_ADDRESS=0x00000000000

# Path to the keystore files exsited,e.g.,"./keystores"
KEYSTORE_PATH="."

# Password for the keystore files generated.
# All keystore files share the same password
KEYSTORE_PASSWORD=123456

# rpc url of bitcoin node, configure the username and password if needed
BTC_RPC_URL=http://your-btc-rpc:8332
BTC_RPC_USERNAME=
BTC_RPC_PASSWORD=

# XSAT Validator account prefix to generate, 
# example: ACCOUNT_PREFIX=ex, the account name will be ex1.sat, ex2.sat, ex3.sat, ...
# the prefix can't be longer than 6 characters. 
# Charaters allowed: a-z, 1-5
ACCOUNT_PREFIX=ex

# Number of XSAT Validator accounts to generate
TOTAL=10

# Amount of xsat tokens for registering one xsat staker, don't modify this.
DEPOSIT_AMOUNT=2100000000000000000000

# testnet contract 0xe9C82be5C9eD3Cee4B99465Bec857395D0d0e502
XSAT_STAKE_HELPER_CONTRACT=0x10CECB61325db0C49201Fc72c50c27AeBd0Ac523

```

**Required Parameters:**

* **`PRIVATE_KEY`**: The private key of the "[Temporary Account](#id-2.-account-setup)**"**, which holds BTC for creating XSAT Validator accounts. To create 10 XSAT Validator accounts, ensure this account has a minimum balance of a little more than 0.001 BTC (10 × 0.0001 BTC)  and a little more BTC for gas fee).\
  Provide the private key starting with "0x" here.
* **`STAKER_REWARD_ADDRESS`**: The address of the "[Stake Account](#id-2.-account-setup)", which holds XSAT for staking and BTC for Validator gas fees.\
  To operate 10 XSAT Validators, ensure this account holds at least 21,000 XSAT (10 × 2,100 XSAT) and sufficient BTC to refilling gas fees for maintaining these validators.\
  At the current gas fee level, each XSAT Validator requires approximately 0.0005 BTC per month.\
  Just provide the EVM address of the Stake Account here.
* **`KEYSTORE_PATH`**: The directory path to store keystore files. Use a relative path, such as `./keystores`, as an example. \
  The keystore file securely stores the private key of the XSAT Validator account. It is encrypted and requires the "KEYSTORE\_PASSWORD" for decryption.
* **`KEYSTORE_PASSWORD`**: The password for the keystore files. All keystore files share the same password.
* **`BTC_RPC_URL`**: The URL of your BTC RPC node. If authentication is required, also provide:
  * `BTC_RPC_USERNAME`
  * `BTC_RPC_PASSWORD`
* **`ACCOUNT_PREFIX`**: The prefix for your XSAT Validator account names. The complete account names will include this prefix followed by sequential numbers or letters. e.g., If `ACCOUNT_PREFIX` is "ex" , the XSAT Validator names will be "ex1.sat", "ex2.sat", ... "exa.sat" in our example.\
  **Notes on `ACCOUNT_PREFIX`:**
  * The total length must not exceed **6 characters**.
  * It can only include lowercase letters (`a-z`) and numbers (`1-5`).
* **`TOTAL`**: The total number of XSAT Validators to create. For example, set this to `10` to run 10 validators.

{% hint style="info" %}

#### Why Separate the Temporary Account and Stake Account? Why Provide the Private Key for the Temporary Account but Only the Address for the Stake Account?

This separation ensures both security and convenience.

Organizations operating multiple XSAT Validators need a clear division of responsibilities between the operations and financial teams.

The operations team handles the deployment and management of XSAT Validators on servers. To streamline this process, the fees for registering XSAT Validator accounts are kept in the Temporary Account. The private key for this account is provided to the script used for batch registration, simplifying operations. Since the Temporary Account contains only enough funds for account registration, it's secure to supply the private key here.

In contrast, the Stake Account holds substantial funds, including XSAT for staking and BTC for gas fees, and is managed by the financial team. For enhanced security, only the Stake Account address is required. The financial team can connect the Stake Account to the dApp interface to perform staking and top up gas fees. Thus, providing just the Stake Account address in the script is sufficient and secure.
{% endhint %}

**Generate XSAT Validator Accounts**

Create the **`KEYSTORE_PATH`**&#x66;older, take "keystores" in current folder as example.

```
mkdir keystores
```

To generate XSAT Validator accounts, execute the following commands:

```bash
yarn install  
yarn cracc
```

This command performs the following actions:

1. **Generate Keystore Files**:
   * Creates a private key for each XSAT Validator.
   * Saves the private keys as encrypted keystore files in the `KEYSTORE_PATH` folder.
   * Secures each keystore file with the `KEYSTORE_PASSWORD`.
2. **Account Creation**:
   * Uses the **Temporary Account** to cover the on-chain resources required for account creation.
   * Uses the **Temporary Account** to Create the XSAT Validator accounts on-chain, with names prefixed by `ACCOUNT_PREFIX`.

After executing these commands, you will have 10 XSAT Validator accounts on the exSat network. The private keys of these accounts will be securely stored as keystore files in the `KEYSTORE_PATH` directory, and the keystore files will be encrypted with the `KEYSTORE_PASSWORD`.

<figure><img src="https://3042747009-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDUBtTPZKYj40o0zqoC8%2Fuploads%2FOBMLIR2NjfidDgagNg9Q%2Fimage.png?alt=media&#x26;token=0a1a8af7-a692-45a7-8ca4-bfedabcf5e40" alt=""><figcaption></figcaption></figure>

#### 2. Stake for Validators and Refill Gas Fees

**This task should be handled by the financial team**.

1. Open the [Validators Portal ](https://portal.exsat.network/)and connect to your [Stake Account](#id-2.-account-setup).
2. [Stake XSAT for your XSAT Validator accounts](https://docs.exsat.network/guides-of-data-consensus/others/operation-references/validator-operations/stake-for-validator-via-xbtc-staking-or-xsat-staking) (2100 $XSAT each) and [refill their gas fees](https://docs.exsat.network/guides-of-data-consensus/others/operation-references/common-operations/refill-btc-for-gas-fees). At the current gas price level, each XSAT Validator requires approximately **0.0005 BTC per month** for gas fees.
3. Use the **"Switch"** button to toggle between different XSAT Validator accounts as needed.

{% hint style="warning" %}
The finance team can also [claim XSAT rewards](https://docs.exsat.network/others/operation-references/validator-operations/stake-for-validator-via-xbtc-staking-or-xsat-staking#claim-rewards) directly on the same page.
{% endhint %}

<figure><img src="https://3042747009-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDUBtTPZKYj40o0zqoC8%2Fuploads%2FpQEfPEjyUE5ChvnkztNi%2Fimage.png?alt=media&#x26;token=c530451f-499d-474b-9ee7-fe0d4a31e7ac" alt="" width="375"><figcaption></figcaption></figure>

#### 3. Generate Docker Compose Configuration File and Run Containers in Batch

**Modify `ognize_cli.sh` File**

```
vim ognize_cli.sh
```

Modify the red parts in the `ognize_cli.sh` file

<figure><img src="https://3042747009-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDUBtTPZKYj40o0zqoC8%2Fuploads%2F923Sc9gPDd5Jugz94sqY%2Fimage.png?alt=media&#x26;token=f547b947-71ca-48e4-8c8b-2c195e8c336f" alt=""><figcaption></figcaption></figure>

* **`BASE_DIR`**:\
  Replace the portion after `:-` with the path specified in the `.env` file for `KEYSTORE_PATH.`

  ```bash
  BASE_DIR="${1:-./keystores}"
  ```
* **`NETWORK`**:\
  Ensure the value matches the `NETWORK` setting in the `.env` file.
* **`EXSAT_RPC_URLS`**:\
  Update this value to match the `EXSAT_RPC_URLS` in the `.env` file.
* **`KEYSTORE_PASSWORD`**:\
  Set this value to match the `KEYSTORE_PASSWORD` in the `.env` file.
* **`BTC_RPC_URL`**:\
  Provide the URL of your BTC RPC node.
  * If authentication is required, replace `"user"` and `"password"` in `BTC_RPC_USERNAME` and `BTC_RPC_PASSWORD` with your BTC RPC credentials.

**Execute the Following Commands:**

```bash
chmod +x ognize_cli.sh
./ognize_cli.sh
```

This command will do below actions:

1. Organize Keystore Files:
   * Creates a folder for each XSAT Validator account under the `KEYSTORE_PATH`.
   * Moves the keystore file for each Validator into its corresponding folder.
   * Generates an `.env` configuration file for each Validator to be used by Docker, you can [edit the .env file](https://docs.exsat.network/guides-of-data-consensus/others/operation-references/common-operations/environment-variables) if needed.
2. Generate `docker-compose.yml`:
   * Creates a `docker-compose.yml` file in the `KEYSTORE_PATH` directory for batch deployment of Docker containers.

After running these commands, the contents of the `KEYSTORE_PATH` directory will appear as follows:

<figure><img src="https://3042747009-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDUBtTPZKYj40o0zqoC8%2Fuploads%2FqeQ5kSzJuzrkZpxeDsDK%2Fimage.png?alt=media&#x26;token=14f44645-eaca-4949-9042-6c62043f323d" alt=""><figcaption></figcaption></figure>

**Start Docker Containers:**

Enter the `KEYSTORE_PATH` folder and Run the command to start the containers. Ensure both Docker and Docker Compose are installed beforehand.

```
cd keystores
docker compose up -d
```

After executing the command, your 10 XSAT Validators will be running in Docker containers. You can monitor the logs for each Validator to verify their operations.

<figure><img src="https://3042747009-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaDUBtTPZKYj40o0zqoC8%2Fuploads%2FVpRUMMG5n11hlSjTUWcH%2Fimage.png?alt=media&#x26;token=38aeac08-8665-4d8c-9484-335ed2ca2f99" alt=""><figcaption></figcaption></figure>

If your Validator Client is operating correctly, the following logs should appear in Docker. Here's [how to view the Docker logs](https://docs.exsat.network/others/operation-references/common-operations/view-logs#running-with-docker):

```
2025-02-28T12:25:23.325+00:00 info: ExsatApi initialized successfully.
2025-02-28T12:25:24.051+00:00 info: Validator[xsatval1.sat] client configurations are correct, and the startup was successful
2025-02-28T12:25:25.499+00:00 info: Endorse task is running
2025-02-28T12:25:26.158+00:00 info: Endorse task is finished
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.exsat.network/guides-of-data-consensus/run-a-xsat-validator/run-multiple-xsat-validators.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
