July 20, 2022

Near | Stake Wars III


Content


Challenge 001

To the content

Source page

â €Create a wallet.


Challenge 002

To the content

Source page

Start a node

â €Check if your server has the right CPU features

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

â €Update packages

sudo apt update && sudo apt upgrade -y

â €Install the required packages

sudo apt install wget jq bc build-essential -y

â €Install Rust

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/installers/rust.sh)

â €Clone the repo

git clone https://github.com/near/nearcore

â €Go to the project folder

cd $HOME/nearcore

â €Switch to the special commit

git switch -c 8448ad1ebf27731a43397686103aa5277e7f2fcf

â €Check the current branch

git branch

â €Build the binary

cargo build -p neard --release --features shardnet

â €Move binary to the folder with all binaries

mv $HOME/nearcore/target/release/neard /usr/bin/

â €Leave the project folder

cd

â €Initialize the node

neard --home $HOME/.near init --chain-id shardnet --download-genesis

Save the file

echo $HOME/.near/node_key.json

â €Download the config file

wget -O $HOME/.near/config.json https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/config.json

â €Edit the config

sed -i -e 's%"archive": false%"archive": true%' $HOME/.near/config.json

â €Create a service file

printf "[Unit]
Description=Near node
After=network-online.target

[Service]
User=$USER
ExecStart=`which neard` --home $HOME/.near run
Restart=on-failure
RestartSec=3
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target" > /etc/systemd/system/neard.service

â €Start the service file

sudo systemctl daemon-reload
sudo systemctl enable neard
sudo systemctl restart neard

â €Add a command to view a log of the node in the system as a variable

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/miscellaneous/insert_variable.sh) -n near_log -v "sudo journalctl -fn 100 -u neard" -a

Becoming a Validator

â €Install Node.js

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/installers/nodejs.sh)

â €Install npm

sudo apt install npm -y

â €Install near-cli

sudo npm install -g near-cli

â €Insert variable with network name

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/miscellaneous/insert_variable.sh) \
-n NEAR_ENV -v "shardnet"

â €Login

near login

â €Answer n.

â €Go to the link through the browser on your PC

â €And grant access

â €Enter an address of the connected account.

â €Add a wallet moniker in the system as a variable

. <(wget -qO- https://raw.githubusercontent.com/SecorD0/utils/main/miscellaneous/insert_variable.sh) -n near_moniker

â €Check if the file exists

cat $HOME/.near/validator_key.json

â €If doesn't exist

⠀Create it (replace POOL_NAME to pool name)

near generate-key "${near_moniker}.factory.shardnet.near"

Save the folder

echo $HOME/.near-credentials/shardnet/

⠀Copy the file generated to shardnet folder

cp "$HOME/.near-credentials/shardnet/${near_moniker}.shardnet.near.json" \
$HOME/.near/validator_key.json

â €Edit it

sed -i -e "s%.shardnet.near%.factory.shardnet.near%; s%private_key%secret_key%" \
$HOME/.near/validator_key.json

â €Restart the node

systemctl restart neard

Challenge 003

To the content

Source page

Staking pool

â €Create staking pool

near call factory.shardnet.near create_staking_pool '{"staking_pool_id": "'${near_moniker}'", "owner_id": "'${near_moniker}'.shardnet.near", "stake_public_key": "'"`jq -r '.public_key' "/root/.near/validator_key.json"`"'", "reward_fee_fraction": {"numerator": 5, "denominator": 100}, "code_hash":"DD428g9eqLL8fWUxv8QSpVFzyHi1Qd16P8ephYCTmMSZ"}' --accountId  "${near_moniker}.shardnet.near" \
--amount 30 --gas 300000000000000

â €Delegate more tokens

near call "${near_moniker}.factory.shardnet.near" deposit_and_stake --accountId "${near_moniker}.shardnet.near" --gas 300000000000000 \
--amount 500

Pinging

â €Install Cron

sudo apt install cron -y

â €Create Cron task to pinging

mkdir -p /etc/cron.hourly/; \
sudo tee <<EOF >/dev/null /etc/cron.hourly/near_ping
#!/bin/bash
near call "${near_moniker}.factory.shardnet.near" ping '{}' --accountId "${near_moniker}.shardnet.near" --gas 300000000000000
EOF

Challenge 004

To the content

Source page

â €S


Challenge 005

To the content

Source page

â €S


Challenge 006

To the content

Source page

â €S


Updating

To the content

â €Go to the project folder

cd $HOME/nearcore

â €Create a branch with the source repository

git remote add upstream https://github.com/near/nearcore

â €Update the local branch to the current branch

git fetch upstream

â €Switch to the special commit

git checkout `wget -qO- https://raw.githubusercontent.com/near/stakewars-iii/main/commit.md`

â €Check the current branch

git branch

â €Build the binary

cargo build -p neard --release --features shardnet

â €Leave the project folder

cd

â €Make backup of the config

cp $HOME/.near/config.json $HOME/.near/config.json.back

â €Make backup of the previous binary

mv /usr/bin/neard $HOME

â €Stop the node

sudo systemctl stop neard

â €Move binary to the folder with all binaries

mv $HOME/nearcore/target/release/neard /usr/bin/

â €Restart the node

sudo systemctl restart neard

â €View the log to make sure the node is running

near_log

Hardforks

To the content

27.07.22

â €Insert hardfork commit as a variable

commit="0d7f272afabc00f4a076b1c89a70ffc62466efe9"

⠀Follow the steps in the «Actions» subsection.

21.07.22

â €Insert hardfork commit as a variable

commit="0f81dca95a55f975b6e54fe6f311a71792e21698"

⠀Follow the steps in the «Actions» subsection.

Actions

â €Go to the project folder

cd $HOME/nearcore

â €Create a branch with the source repository

git remote add upstream https://github.com/near/nearcore

â €Update the local branch to the current branch

git fetch upstream

â €Switch to the special commit

git checkout $commit

â €Check the current branch

git branch

â €Build the binary

cargo build -p neard --release --features shardnet

â €Make backup of the previous binary

mv /usr/bin/neard $HOME

â €Stop the node

sudo systemctl stop neard

â €Move binary to the folder with all binaries

mv $HOME/nearcore/target/release/neard /usr/bin/

â €Delete previous data

rm -rf $HOME/.near/{data,genesis.json}

â €Download the genesis file

wget -O $HOME/.near/genesis.json https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/genesis.json

â €Download the config file

wget -O $HOME/.near/config.json https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/config.json

â €Edit the config

sed -i -e 's%"archive": false%"archive": true%' $HOME/.near/config.json

â €Restart the node

sudo systemctl restart neard

â €View the log to make sure the node is running

near_log

Useful links

To the content

Event website

GitHub binary

GitHub challenges

Wallet

Explorer