---
# System prepended metadata

title: Untitled

---

With hive-engine coming out with their P2P validation layer recently, I thought it might be useful to make a guide in order to help users who want to get set up. While this isn't a true block production layer, it's better than nothing since it can help show if particular nodes are out of sync(though if everyone just uses the "official" node, then the p2p layer is kinda useless, so use other nodes developers).

I decided to write a simple guide so that way anyone who wants to use the programs can do so. I'm assuming you know the basics of how to connect to a server, and how to do basic troubleshooting(if it says "error something's not installed, go ahead and install it) as well as basic security stuff for your server(PLEASE USE SSH KEYS AND NOT PASSWORD). I'm also using Ubuntu 20.04 while writing this, if you are on other systems it might vary. You'll need a server with at least 4 gigs of ram (or 2gb and some swap, but real ram is always better) and I'd recommend at least 2 cores and 30 GB of SSD.

When you get your server you'll want to install a few basic things, including git, nodejs, mongodb and screen.

```
sudo apt-get update -y

sudo apt-get upgrade -y

sudo apt install git -y

sudo apt install screen -y

sudo apt install npm -y

sudo apt install ufw -y


wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list

sudo apt-get update

sudo apt-get install -y mongodb-org
```

This should install the packages that we need. Next we'll need to change our mongo settings to use replication sets. If you have any problems, feel free to consult https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/.

```
sudo nano /etc/mongod.conf
```

On it you'll see a line that looks like `#replication:`

You'll want to change it so that you remove the # at the start and on the line below it, add two spaces and `replSetName: "rs0"`. The final result should look like: 

```
replication:
  replSetName: "rs0"
```

Now save that, Press control + O, then control + X.

Next we'll restart mongod.

```
sudo systemctl stop mongod
sudo systemctl start mongod
```

Could also use restart here, but I like stop and start :)


Now we want to activate replica sets on mongodb. 

```
mongo
rs.initiate()
```

You'll see a bunch of stuff and it should say something like "rs0"... at the bottom left. If thats all good, press control + D to exit. 

Now we'll want to update our version of nodejs. 

```
sudo npm i -g n
sudo n latest
```

At this point please disconnect and reconnect to the server. It's the easiest way for the update to take place.

Now the following step you want to take ONLY IF YOU GOT A 2 GB RAM SERVER!!! While it won't hurt it if you do on a 4 GB server, it's not necessary. But it is required on a 2 GB server. This is making a swap file on your server, because mongo import takes more than 2 GB of ram. If you have any problems feel free to consult https://linuxize.com/post/create-a-linux-swap-file/. We'll be making a 2GB swap file.

```
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
```

Now if you do `sudo swapon --show` you should see some number and under size it should be `2048M` showing you did it all correctly. 

The following steps are for everyone again. 

We'll want to grab the latest snapshot for engine from a source. I provide snapshots over at https://cdn.rishipanthee.com/hiveengine/ (grab the one with the latest date), and the official engine snapshot can be found at http://api2.hive-engine.com/hsc_20210203_b50993579.archive. For this example we'll be using the snapshot from engine as I regularly update mine and delete older ones and so the dates can change. 

```
wget http://api2.hive-engine.com/hsc_20210203_b50993579.archive
```
We wait for that to finish. Take note of the name of the file, here it is `hsc_20210203_b50993579.archive`. If you grab one of a different name, you'll need to update what you do on the following step to match the name.

Then we'll want to import in the snapshot onto mongodb. For this we use a screen so that way if you disconnect it still works as this is the longest part. If you got the bare minimum specs, it'll take about 20 minutes. 

```
screen -S reload
mongorestore --gzip --archive=hsc_20210203_b50993579.archive
```

If you know how to get out of a screen, you can do so and move onto other steps while waiting for this to finish. If you don't, just sit tight, you can wait a little bit. If you get disconnected from your server and need to reconnect to the screen you can type in `screen -r reload`. Once it's done, you can press control + D to disconnect from the screen. 

Up next is getting the hive engine code. We use git to get this. Yes it is still called steem smart contracts.

```
git clone https://github.com/hive-engine/steemsmartcontracts.git 
cd steemsmartcontracts
git checkout heRelease1.1
```
Now if you are following this guide at a point when 1.1 is old, just replace it with the name of the branch of the latest release. Go ask them for what it is.

Then we want to install the dependencies to the program as well as pm2 which we will use to run this in the background.

```
npm i
sudo npm i -g pm2
```

You'll want to then modify the config file to work with the import we got, to open it type in `nano config.json`, as well as add or remove nodes. The list is pretty good right now, the only thing you'll want to change is the part after ` "startHiveBlock": ` to be 0. Final result should look like:

```
 "startHiveBlock": 0,
```

Make sure the comma after that is there. On the last line, there's `witnessEnabled` which should say false for now, change that to true. Result should be like:

```
"witnessEnabled": true
```

Save the file and exit, control + O, control + X.

Now we need to move the example env file to be a real one. 

```
mv .env.example .env
nano .env
```

Now this is all blank. You'll want to fill it in with your details, after the = on each line. 

Once you do that, control + O, control + X to save and exit.

Almost there. Now we want to allow access to the ports that are necessary for this.

```
sudo ufw allow 5000
sudo ufw allow 5001
```

Now we start the node up. 

```
pm2 start app.js --no-treekill --kill-timeout 10000 --no-autorestart --name engwit
```

Now we need to wait for it to sync. This can take some time. The older the snapshot that you use, the longer it takes. To monitor your progress, type in `pm2 logs`. Once you see lines that look like `0|app      | 2021-02-03 03:15:04 info: [Streamer] head_block_number 50994938 currentBlock 50994939 Hive blockchain is 0 blocks ahead` you are good to go. The 0 blocks ahead part is very important. Otherwise you could miss blocks. You can disconnect while waiting at this point. To close the logs, press control + C.


Once thats up and running, you might need to cd back into the folder `cd steemsmartcontracts` if you exited the connection to the server. 

Then enable your witness

```
node witness_action.js register
```

And you did it. You are now a witness. Be sure to vote for me for Hive witness (@hextech) as well as hive-engine witness(@h-e). To vote for hive engine witnesses, you can check it out at https://cdn.rishipanthee.com/enginewit.html. 


