# Installation instructions


- - -

## Environment-dependent installation
1.Install the Java1.8 environment.

For example, using apt-get to install Ubuntu:


```bash
apt-get install openjdk-8-jre
```
On Centos, install using yum:


```bash
yum install java-1.8.0-openjdk
```

In an offline environment, download the OpenJDK installation package and install it offline.

Under the Ubuntu

```bash
dpkg -i jdk-8uxxxxx.deb
```

On Centos, use yum for offline installation:

```bash
yum localinstall jdk-8u271-linux-xxx.rpm
```

2.Install wGET and unzip. For example, using apt-get to install Ubuntu:


```bash
apt-get install unzip
apt-get install wget
```

- - -

## Network Topology Description

Only one node is required to deploy the Surui smart contract engine, which can be used for debugging and testing. The multi-node mode cannot be used to achieve trusted computing. When a single node is deployed, the calculation of “anti-repudiation” can be implemented by configuring the ledger, but the calculation of “tamper-resistant” cannot be implemented.

In multi-node deployment, the following figure shows three types of logical nodes. One to three types of nodes can be installed on a VM.

1) Account node. That is, the number Rui schema ledger.

2) Contract node. Run code logic and implement highly responsive modules through memory caching. Form a trusted computing network with other contract nodes.

3) Routing node. Routing information of each contract node. Generally, a routing node can support a maximum of 1000 contract nodes. Deploy multiple routing nodes as required, and configure the routing nodes among them to implement a large-scale node network.

Generally, **Contract node and ledger node** is deployed on the same VM.

![deploytopology](_static/imgs/deploytopology.png)

- - -

## Smart contract node installation

Open the[安装包下载链接](https://public.internetapi.cn/?dir=releases/bdcontract/newest), download `bdserver-lite.zip` or `bdserver.zip`, among them, the `bdserver.zip` contains more examples and documentation. After downloading, unzip and launch.


```bash
unzip -d ./bdserver bdserver-lite.zip
cd bdserver
chmod +x *.sh
sh cmstart.sh
```

- - -

## Route admission nodes are installed

Open[安装包下载链接](https://public.internetapi.cn/?dir=releases/bdcontract/newest) Where, download `bdserver-cluster.zip`. After downloading, unzip and launch.


```bash
unzip -d ./bdcluster bdserver-cluster.zip
cd bdcluster
chmod +x *.sh
sh ncstart.sh
```

- - -

## Document describing

### Smart Contract node

![bdserver目录](_static/imgs/dirstructure.png)

Description of files in this directory:

1.Cmstart. sh This script is used to start the contract engine. The contract engine listens to port 8080 by default. You can modify the listening port by running the cmstart.sh command.

2.BDWareProjectDir This directory stores all contract projects for this node.

3.WebContent This directory stores the front-end code of this node.

4.Cp, which holds yjs.jar, the JAR needed to start the contract instance.

5.Bdserver. jar provides HTTP/webSocket server logic externally.

6.Updatecontract. sh Upgrade script.

### Route admission node

The installation script is automatically downloaded and decompressed to the bdCluster directory. Description of files in this directory:

1.Ncstart. sh This script is used to start the node access center. It listens on port 1718 by default. You can modify the listening port by modifying ncstart.sh.

2.WebContent This directory houses the front-end code for the access center.

3.Bdcluster. jar back-end of the access center.

- - -

## The upgrade process

### Contract node

On the command line, type:


```bash
sh updateContract.sh
```

Alternatively, go to [public.internetapi.cn](https://public.internetapi.cn/?dir=releases/bdcontract), download the latest file, and upgrade yjs.zip/bdserver-jar.zip/AgentWebContent separately.

### Route admission node


```bash
sh updateCluster.sh
```
Through the [public.internetapi.cn](https://public.internetapi.cn/?dir=releases/bdcontract), download the latest files, separate upgrade bdserver — cluster. Zip/ClusterWebContent. Zip to upgrade.

- - -

## Directions for use

### Use it on the reference page
If the WebContent directory is reserved, you can configure it using the browser. For more information, see the document [BDContract refer to the interface instructions](./IDEUsage.html) on the left.

#### BDWare OnlineIDE
Open [BDWare OnlineIDE](../OnlineIDE.html).

#### BDWare NodePortal
Open [BDWare NodePortal](../NodePortal.html).

If the cross-node function is required for networking, install the route access center. Perform the following steps to configure it. Two sets of public and private keys are involved. The first group of public and private keys is the public and private keys of the contract node that have NodeManager permission. The second group is the public and private keys of the route access node that have the CenterManager permission.

1.Open nodeportal. HTML and copy the public and private NodeManager keys of the node.

2.Open centerportal. HTML, click in the upper right corner, and import the public and private NodeManager keys. And select “NodeManager” for identity authentication.

3.In centerportal. HTML, switch the public and private keys of CenterManager, click User Management on the left, and pass the NodeManager authentication request.

4.Use the public and private keys of the NodeManager permission to open nodeportal. HTML, click the Node Management menu, and configure joining the network. The format of joining the network is WS :// IP address of Centerportal: port +1. ![配置示例](_static/imgs/config.png)


### Using the SDK

#### Basic knowledge of

[Websocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)

[Sm2 encrypted using] (https://github.com/JuneAndGreen/sm-crypto)

#### Download the SDK

1. Java client download: [BDWareJavaClient](_static/BDWareJavaClient.zip). For details about how to use it, download it, decompress it, check readme.md, and see [ContractAPI](./ContractAPI.html).

2.Javascript version for client download :[BDWareWebClient](_static/BDWareWebClient.zip). For details about how to use it, download it, decompress it, check readme.md, and see [ContractAPI](./ContractAPI.html).

3.Configuration tool [BDWareConfigTool](_static/BDWareConfigTool.zip). For details, decompress the package and run the following command to view help information:


``` bash
java -jar java-client.jar -h
```