Staking4All
4 min readSep 7, 2022

--

We have put together a step-by-step guide on how to set up your Near validator. You will need to create a Linux based instance on your preferred Cloud provider. Amazon Web Services, Google Cloud Platform, Vultr and IBM Cloud are some examples of reliable Cloud providers.

Update Ubuntu

sudo apt-get update
sudo apt-get upgrade

Install the developer tools (nodejs and npm)

curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -  
sudo apt install build-essential nodejs
PATH="$PATH"
sudo apt install nodejs

Use these commands to check your node.js and npm versions

node -v
npm -v

Create a user

sudo adduser <USERNAME>
sudo usermod -a -G sudo <USERNAME>
su - <USERNAME>

Install the Near CLI

sudo npm install -g near-cli
export NEAR_ENV=shardnet
echo 'export NEAR_ENV=shardnet' >> ~/.bashrc

Near CLI Commands

Proposals: A validator’s proposal indicates they would like to enter the validator set, but they must meet the minimum seat price in order to be accepted.

near proposals

Current Validators: This list shows the active validators in the current epoch, the number of blocks expected, the number of blocks produced, as well as the online rate.

near validators current

Next Validators: This list shows the validators that will be active in the next epoch. These validators proposals were accepted in the previous epoch.

near validators next

Create a Wallet

Go to https://wallet.shardnet.near.org/ to create a wallet. Follow the steps to create your wallet.

Set Up the Node

We are going to test to make sure that the CPU is supported

lscpu | grep -P '(?=.*avx )(?=.*sse4.2 )(?=.*cx16 )(?=.*popcnt )' > /dev/null \
&& echo "Supported" \
|| echo "Not supported"

Installing all essential softeware

sudo apt install -y git binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev cmake gcc g++ python docker.io protobuf-compiler libssl-dev pkg-config clang llvm cargosudo apt install python3-pipUSER_BASE_BIN=$(python3 -m site --user-base)/bin
export PATH="$USER_BASE_BIN:$PATH"
sudo apt install clang build-essential makecurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shsource $HOME/.cargo/env

Next, we download the Near code and compile the binary. We need to use the latest ‘commit’ which you can find here.

git clone https://github.com/near/nearcore
cd nearcore
git fetch
git checkout <commit>cargo build -p neard --release --features shardnet

We add the genesis and config file for shardnet

./target/release/neard --home ~/.near init --chain-id shardnet --download-genesisrm ~/.near/config.json
wget -O ~/.near/config.json https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/config.json
cd ~/.near
wget https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/genesis.json

Now we start the node

cd ~/nearcore
./target/release/neard --home ~/.near run

Create the Validator

We use this command to launch a web browser

near login
  1. Copy the link in the browser
  2. Grant access to the Near CLI
  3. Once you have granted access, a page will pop up saying “This site can’t be reached”
  4. Go back to your console, enter your wallet and press enter

Check the validator_key.json

cat ~/.near/validator_key.json

Run this command to create a key file if you don’t have one

near generate-key <pool_id>

NOTE:

Your pool_id is <your_pool_name>.factory.shardnet.near

eg: hansolo4.factory.shardnet.near

Your wallet name eg: hansolo4.shardnet.near

Your pool name eg: hansolo4

Copy the file. Remember to replace <pool_id> with your own

cp ~/.near-credentials/shardnet/<pool_id>.json ~/.near/validator_key.json

Make a Service

We make a service file

sudo nano /etc/systemd/system/neard.service

Paste the following in the file

[Unit]
Description=NEARd Daemon Service
[Service]
Type=simple
User=near
#Group=near
WorkingDirectory=/home/near/.near
ExecStart=/home/near/nearcore/target/release/neard run
Restart=on-failure
RestartSec=30
KillSignal=SIGINT
TimeoutStopSec=45
KillMode=mixed
[Install]
WantedBy=multi-user.target

Use these commands to test the service and make sure it is working

sudo systemctl enable neard
sudo service neard start
sudo service neard status

Check the Service Logs

Install

sudo apt install ccze

We can use either of the following commands to check our logs

journalctl -n 100 -f -u neardORjournalctl -n 100 -f -u neard | ccze -A

Deploy a Staking Pool

near call factory.shardnet.near create_staking_pool '{"staking_pool_id": "<pool name>", "owner_id": "<accountId>", "stake_public_key": "<public key>", "reward_fee_fraction": {"numerator": 5, "denominator": 100}, "code_hash":"DD428g9eqLL8fWUxv8QSpVFzyHi1Qd16P8ephYCTmMSZ"}' --accountId="<accountId>" --amount=30 --gas=300000000000000

Remember that if your pool id is hansolo4.factory.shardnet.near then

  • your <pool name>is hansolo4
  • your <accountId>is hansolo4.shardnet.near

To change pool parameters

near call <pool_id> update_reward_fee_fraction '{"reward_fee_fraction": {"numerator": 1, "denominator": 100}}' --accountId <account_id> --gas=300000000000000

To stake Near

near call <pool_id> deposit_and_stake --amount <amount> --accountId <accountId> --gas=300000000000000

To ‘unstake’ Near

near call <pool_id> unstake '{"amount": "<amount yoctoNEAR>"}' --accountId <accountId> --gas=300000000000000

To ‘unstake’ ALL Near

near call <pool_id> unstake_all --accountId <accountId> --gas=300000000000000

To withdraw Near. This will take 2–3 epochs to complete

near call <pool_id> withdraw '{"amount": "<amount yoctoNEAR>"}' --accountId <accountId> --gas=300000000000000

To withdraw ALL Near

near call <pool_id> withdraw_all --accountId <accountId> --gas=300000000000000

To ping. You should issue a ping each epoch to keep your rewards current

near call <pool_id> ping '{}' --accountId <accountId> --gas=300000000000000

To check your total balance

near view <pool_id> get_account_total_balance '{"account_id": "<accountId>"}'

To check your staked balance

near view <pool_id> get_account_staked_balance '{"account_id": "<accountId>"}'

To check your ‘unstaked’ balance

near view <pool_id> get_account_unstaked_balance '{"account_id": "<accountId>"}'

To withdraw funds. Remember that your can only withdraw your ‘unstaked’ funds

near view <pool_id> is_account_unstaked_balance_available '{"account_id": "<accountId>"}'

Done

You should now have a fully running validator node

--

--