# Installation

## Running a Change Chain Node from Source

Before you begin, ensure your system meets the following software requirements:

* **Operating System**: Ubuntu 18.04 or later (Linux), macOS, or Windows Subsystem for Linux (WSL)
* **Go Programming Language**: Version 1.16 or later
* **Git**: Latest version
* **gcc (GNU Compiler Collection)**: For compiling source code

#### 1. Install Go

**Linux/macOS**

Download and install Go:

```
# For Linux
wget https://golang.org/dl/go1.17.2.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.17.2.linux-amd64.tar.gz

# For macOS
brew install go
```

Add Go to your PATH:

```bash
bashCopy codeecho "export PATH=$PATH:/usr/local/go/bin" >> ~/.bashrc
source ~/.bashrc
```

Verify the installation:

```bash
bashCopy codego version
```

**Windows**

Download the Windows installer from the [official Go website](https://golang.org/dl/) and follow the installation instructions.

#### 2. Install Git

**Linux**

```bash
bashCopy codesudo apt-get update
sudo apt-get install git
```

**macOS**

```bash
bashCopy codebrew install git
```

**Windows**

Download and install Git from the [official website](https://git-scm.com/download/win).

#### 3. Install gcc

**Linux**

```bash
bashCopy codesudo apt-get install build-essential
```

**macOS**

```bash
bashCopy codexcode-select --install
```

***

### Build and Start the Change Chain Node

#### 1. Set the `GOPATH`

Set your Go workspace directory:

```bash
bashCopy codeexport GOPATH=$HOME/go
echo "export GOPATH=$HOME/go" >> ~/.bashrc
source ~/.bashrc
```

#### 2. Create a Directory in Your `GOPATH`

Create the necessary directories:

```bash
bashCopy codemkdir -p $GOPATH/src/github.com/changechain
```

#### 3. Clone the Change Chain Repository

Navigate to the directory and clone the repository:

```bash
bashCopy codecd $GOPATH/src/github.com/changechain
git clone https://github.com/changechain/changechain.git
```

#### 4. Run the Build Script

Navigate to the cloned repository and run the build script:

```bash
bashCopy codecd $GOPATH/src/github.com/changechain/changechain
./scripts/build.sh
```

This script compiles the Change Chain node and places the executable in the `build` directory.

#### 5. Start the Node

**On Change Chain Mainnet**

```bash
bashCopy codecd $GOPATH/src/github.com/changechain/changechain
./build/changechain
```

**On Testnet**

```bash
bashCopy codecd $GOPATH/src/github.com/changechain/changechain
./build/changechain --network-id=testnet
```

**Note:** To stop the node, press `Ctrl + C`.

***

### Run with a Pre-Built Binary

If you prefer to use a pre-built binary instead of building from source, follow these steps:

#### 1. Download

Visit the [Change Chain Releases page](https://github.com/changechain/changechain/releases) and download the appropriate version for your operating system.

**MacOS**

* Download: `changechain-macos-<VERSION>.zip`
* Unzip:

  ```bash
  bashCopy codeunzip changechain-macos-<VERSION>.zip
  ```

  The resulting folder `changechain-<VERSION>` contains the binaries.

**Linux (x86\_64 PCs or Cloud Providers)**

* Download: `changechain-linux-amd64-<VERSION>.tar.gz`
* Unzip:

  ```bash
  bashCopy codetar -xvf changechain-linux-amd64-<VERSION>.tar.gz
  ```

  The resulting folder `changechain-<VERSION>-linux` contains the binaries.

#### 2. Start the Node

**MacOS**

**Mainnet:**

```bash
bashCopy code./changechain-<VERSION>/build/changechain
```

**Testnet:**

```bash
bashCopy code./changechain-<VERSION>/build/changechain --network-id=testnet
```

**Linux**

**Mainnet:**

```bash
bashCopy code./changechain-<VERSION>-linux/changechain
```

**Testnet:**

```bash
bashCopy code./changechain-<VERSION>-linux/changechain --network-id=testnet
```

***

### Networking

To successfully run the Change Chain node and participate in the network, ensure that your node can accept connections on network port `9651`.

#### Running on a Cloud Provider

If you're running your node on a cloud service like AWS, Azure, or Google Cloud:

* Configure your cloud instance's firewall settings to allow inbound and outbound traffic on port `9651`.
* Ensure your security groups and network access control lists (ACLs) permit traffic on this port.

#### Running on a Home Connection

If you're running your node from home:

* Set up port forwarding on your router to forward external traffic on port `9651` to your machine's local IP address.
* Check your computer's firewall settings to allow traffic on port `9651`.

**Note:** To make API calls to your node from other machines, include the argument `--http-host=0.0.0.0` when starting the node:

```bash
bashCopy code./build/changechain --http-host=0.0.0.0
```

***

### Bootstrapping

When starting your node for the first time, it needs to catch up with the latest network state, a process known as bootstrapping. This may take several hours depending on your internet connection and hardware performance.

#### Check Bootstrapping Progress

You can check if your node has finished bootstrapping a particular chain by using the `info.isBootstrapped` API method.

**Example Command**

```bash
bashCopy codecurl -X POST --data '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "info.isBootstrapped",
    "params": {
        "chain": "C"
    }
}' -H 'content-type:application/json;' 127.0.0.1:9651/ext/info
```

Replace `"chain": "C"` with `"X"` or `"P"` to check the status of the other chains.

**Interpreting the Response**

* If the response returns `true`, the chain has finished bootstrapping.
* If the response returns `false`, the chain is still bootstrapping.

***

### RPC Endpoints

Once your node has bootstrapped, the following RPC endpoints become available:

* Change Chain: `http://localhost:9651/ext/bc/C`

If accessing remotely, replace `localhost` with your node's public IP address.

For detailed API documentation, refer to the Change Chain API Reference.


---

# 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://change-chain-1.gitbook.io/change-chain/mining/mining/installation.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.
