How to compile nearcore

Nodesanna
2 min readJun 16, 2020

I have already seen several tutorials on how to compile nearcore, but I haven’t seen any information on how to transfer my node to another server with minimal uptime loss, so in this article I decided to combine these two questions.

1. Update system and create contract for staking pool
Update ubuntu:

sudo apt-get update
sudo apt install build-essential
sudo apt install git2

First of all I’v made staking pool contract on my new VPS. Let’s clone contract:

git clone https://github.com/htafolla/initial-contracts.git

Install rust:

curl proto '=https' - tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env

Add wasm target:

rustup target add wasm32-unknown-unknown

Create contract:

cd initial-contracts/staking-pool
./build.sh

Since in this article I am just transferring data from one server to another, I will not create a new staking pool.

2. Compile nearcore from Github

Let’s make necessary changes and install some updates.:

rustup default nightly
sudo apt install make clang pkg-config libssl-dev libclang-dev g++ g++-multilib build-essential

Clone nearcore and compile it. All releases can be viewed here: https://github.com/nearprotocol/nearcore/releases At the time of writing, the latest version of betanet is 1.9.0-beta.2, and testnet — 1.8.0-rc.3. Accordingly, to compile in betanet, enter the following commands:

git clone https://github.com/nearprotocol/nearcore.git
cd nearcore/ && git checkout tags/1.9.0-beta.2
make release

Install nearup and start the node!:

curl --proto '=https' --tlsv1.2 -sSfL https://up.near.dev | python3
source $HOME/.nearup/env
nearup betanet --nodocker --binary-path ~/nearcore/target/release/

Don’t enter account ID further, just leave empty and press ‘Enter’

Let your node synchronized.

3. Install node js & near cli

Install node js:

curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
sudo apt install nodejs

Install near shell and go to betanet:

npm install near-cli -g
export NODE_ENV=betanet

4. Copy/paste files

Copy & paste following files from your old server to new one (I used WinSCP tool for it):
$HOME/.near/betanet/config.json
$HOME/.near/betanet/node_key.json
$HOME/.near/betanet/validator_key.json

And this folder:
$HOME/.near-credentials/betanet

5. The final!

Check that your node synchronized.
After that you should stop-start the node:

nearup stop
nearup betanet --nodocker --binary-path ~/nearcore/target/release/

And stop your old node.

PS. My pool is “valeraverim”

--

--