Setting up a Shardnet Node for NEAR STAKEWARS!
Firstly you will need a server! You can use 8 cpu 16 RAM on Hetzner.
Registration form here!
Update Ubuntu and download all the needed packages, install python
sudo apt update && sudo apt upgrade -ysudo apt install -y git binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev cmake gcc g++ python docker protobuf-compiler libssl-dev pkg-config clang llvm cargo clang build-essential makesudo apt install python3-pip
USER_BASE_BIN=$(python3 -m site --user-base)/bin export PATH="$USER_BASE_BIN:$PATH"
Install Node JS and NPM
curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install build-essential nodejs
PATH="$PATH"
Install NEAR CLI
sudo npm install -g near-cli
Set up the environment. Be aware that you should input these commands anytime you open a new session! Otherwise testnet environment will be used!
export NEAR_ENV=shardnet
echo ‘export NEAR_ENV=shardnet’ >> ~/.bashrc
source ~/.bashrc
Install cargo and rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
Now download and build binary. Please check the commit to be exactly this since it is the only one that should be used right now!
git clone https://github.com/near/nearcore
cd nearcore
git fetch
git checkout 0f81dca95a55f975b6e54fe6f311a71792e21698
cargo build -p neard --release --features shardnet#check the version
~/nearcore/target/release/neard --version
Initialize the working directory, delete old files and download new config file and new genesis.json. Since the network was hard forked recently, there is no need to download the snapshot.
~/nearcore/target/release/neard --home ~/.near init --chain-id shardnet --download-genesis
rm ~/.near/config.json ~/.near/genesis.json
wget -O ~/.near/config.json https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/config.json
wget -O ~/.near/genesis.json https://s3-us-west-1.amazonaws.com/build.nearprotocol.com/nearcore-deploy/shardnet/genesis.json
Now you will need to create a wallet https://wallet.shardnet.near.org/
WARNING! If you had a wallet previously to the hard fork, you may need to recreate it! Forget the old mnemonic and do everything from scratch.
After that, write in the CLI
near login
See the authorisation link and copy it into the browser window where you wallet is opened. After connecting a wallet, right the wallet name (<accountId>.shardnet.near) in the CLI and confirm.
Copy your wallet json and make some changes
cd ~/.near-credentials/shardnet/
cp wallet.json ~/.near/validator_key.json
nano validator_key.json
Change the account ID and Private Key parameter accordingly, then exit nano editor.
{
"account_id": "xx.factory.shardnet.near",
"public_key":"ed25519:HeaBJ3xLgvZacQWmEctTeUqyfSU4SDEnEwckWxd92W2G", "secret_key": "ed25519:****"
}
Create a service file (one command)
sudo tee /etc/systemd/system/neard.service > /dev/null <<EOF
[Unit]
Description=NEARd Daemon Service
[Service]
Type=simple
User=$USER #Group=near
WorkingDirectory=$HOME/.near ExecStart=$HOME/nearcore/target/release/neard run
Restart=on-failure
RestartSec=30
KillSignal=SIGINT
TimeoutStopSec=45
KillMode=mixed
[Install]
WantedBy=multi-user.target
EOF
Now start the service and see logs, that everything works fine. You should see it downloading headers firstly and the blocks. Waiting for full sync.
sudo systemctl daemon-reload
sudo systemctl enable neard
sudo systemctl start neard
journalctl -f -u neard
Now let’s deploy a contract of our staking pool with 30 NEAR staked!
near call factory.shardnet.near create_staking_pool '{"staking_pool_id": "<pool id>", "owner_id": "<accountId>", "stake_public_key": "<public key>", "reward_fee_fraction": {"numerator": 5, "denominator": 100}, "code_hash":"DD428g9eqLL8fWUxv8QSpVFzyHi1Qd16P8ephYCTmMSZ"}' --accountId="<accountId>" --amount=30 --gas=300000000000000
Change <pool id>, <accountId>, <public key>, <accountId> parameters here!
My example for this
near call factory.shardnet.near create_staking_pool '{"staking_pool_id": "777stakes", "owner_id": "777stakes.shardnet.near", "stake_public_key": "ed25519:FS6KjVhKNaZHnwrSerQBPLJLJGYZkH66j9FNbALHWYz5", "reward_fee_fraction": {"numerator": 5, "denominator": 100}, "code_hash":"DD428g9eqLL8fWUxv8QSpVFzyHi1Qd16P8ephYCTmMSZ"}' --accountId="777stakes.shardnet.near" --amount=30 --gas=300000000000000
If everything is fine, you should see yourself in near proposals command. Let’s look at the seat price in the bottom of near proposals command. And then we will need to stake. Remember to set environmentals for shardnet!
near proposals
Change parametres for staking accordingly!
near call stakes.factory.shardnet.near deposit_and_stake --amount 1200 --accountId 777stakes.shardnet.near --gas=300000000000000
In the few epochs, you will be able to see yourself in the explorer and by typing
near validators current
near validators next
Finally, we can set the ping (every 5 minutes)
nano ping.shexport NEAR_ENV=shardnet
near call 777stakes.factory.shardnet.near ping '{}' --accountId 777stakes.shardnet.near --gas=300000000000000exit nanochmod +x ping.sh
Set up cron job for every 5 minutes! You can make sure script is working in the explorer!
crontab -e
*/5 * * * * $HOME/ping.sh >> $HOME/ping.log
Now all set! Good luck!