Skip to content

Sensei-Node/near

Repository files navigation

Introduction

Deploy Server

  • For this guide we have used an Azure VM to install the Near node, we have used their CLI but it could also be deployed trough their website.

Azure_VM

  • The important thing is that the machine meets the minimum requirements for Near to run and sufficient disk to store the blockchain. For shardnet chunk producers, the required hardware is as following:
Hardware Chunk-Only Producer Specifications
CPU 4-Core CPU with AVX support
RAM 8GB DDR4
Storage 500GB SSD

Installation

  • First we will upgrade the OS and dependencies
sudo apt update && sudo apt upgrade -y
  • Install developer tools, 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 the environment for your Near-CLI (shardnet or mainnet)
export NEAR_ENV=shardnet
  • You can make the env persistent adding it to ~/.profile or ~/.bashrc (depending on the OS).

Installing the Node

  • Install Developers tools:
sudo apt install -y git binutils-dev libcurl4-openssl-dev zlib1g-dev libdw-dev libiberty-dev cmake gcc g++ python protobuf-compiler libssl-dev pkg-config clang llvm cargo
  • Make sure python3 pip is install, if not proceed to install it:
sudo apt install python3-pip
  • Install Rust and Cargo:
curl --proto '=https' --tlsv1.2 -sSf [https://sh.rustup.rs](https://sh.rustup.rs/) | sh
source $HOME/.cargo/env
  • Clone the Near Core repository:
git clone https://github.com/near/nearcore
  • Navigate to nearcore folder:
cd nearcore
  • Run the following command:
git fetch
git checkout <commit>
  • Build binaries (ignore shardnet flag for mainnet):
cargo build -p neard --release --features shardnet
  • Create working directory
./target/release/neard --home ~/.near init --chain-id shardnet --download-genesis
"tracked_shards": [0]
"archive": false
"boot_nodes": "<INSERT BOOTNODES>"
  • Start the node
./target/release/neard --home ~/.near run

Installing and Start the Node

Create Validator

  • Link your wallet to your created account:
near login

Near Login

  • You must then go to the link provided in your console and grant access to your account.

Near Login Grant Access

  • After that, you will need to create the validator key.
near generate-key <pool_id>
<pool_id> == xx.factory.shardnet.near WHERE xx is you pool name, for example senseinode.factory.sharednet.near
  • Move the newly created file to your ~/.near directory:
`cp ~/.near-credentials/shardnet/YOUR_WALLET.json ~/.near/validator_key.json`
  • File must follow this pattern, make sure to change private_key for secret_key if necessary:
{
"account_id": "xx.factory.shardnet.near",
"public_key": "ed25519:HeaBJ3xLgvZacQWmEctTeUqyfSU4SDEnEwckWxd92W2G",
"secret_key": "ed25519:****"
}
  • Stop and start your Validator Node again, you should see the validator flag in the logs:

Start Validator Node

Register Staking Pool

  • The following commands will use senseinode.shardnet.near account and senseinode.factory.shardnet.near as the staking pool, you must modify these parameters and the public keys to create your own staking pools.

Create Staking Pool

near call factory.shardnet.near create_staking_pool '{"staking_pool_id": "senseinode", "owner_id": "senseinode.shardnet.near", "stake_public_key": "ed25519:EfTpUmWR369JqZVf7UnrFsyQVXQ3fhFvNqbhMiDZEGU2", "reward_fee_fraction": {"numerator": 5, "denominator": 100}, "code_hash":"DD428g9eqLL8fWUxv8QSpVFzyHi1Qd16P8ephYCTmMSZ"}' --accountId="senseinode.shardnet.near" --amount=30 --gas=300000000000000

Stake

near call senseinode.factory.shardnet.near deposit_and_stake --amount 200 --accountId senseinode.shardnet.near --gas=300000000000000

Ping

near call senseinode.factory.shardnet.near ping '{}' --accountId senseinode.shardnet.near --gas=300000000000000

Balances

near view senseinode.factory.shardnet.near get_account_total_balance '{"account_id": "senseinode.shardnet.near"}'

View Staked Balances

near view senseinode.factory.shardnet.near get_account_staked_balance '{"account_id": "senseinode.shardnet.near"}'

Pause

near call senseinode.factory.shardnet.near pause_staking '{}' --accountId senseinode.shardnet.near

Resume

near call senseinode.factory.shardnet.near resume_staking '{}' --accountId senseinode.shardnet.near

Check Validator Info

curl -s -d '{"jsonrpc": "2.0", "method": "validators", "id": "dontcare", "params": [null]}' -H 'Content-Type: application/json' [http://localhost:3030/](http://localhost:3030/)

Monitor Your Validator

  • The following script is the base for a monitor tool that checks your validator status. Make sure to change the staking_pool variable to your own pool name.
import requests as r
import json

url = 'http://localhost:3030'

data = json.dumps({"jsonrpc": "2.0", "method": "validators", "id": "dontcare", "params": "latest"})

headers = {'content-type': 'application/json'}

res = r.post(url, headers = headers, data = data).json()

#input your staking pool
staking_pool = 'senseinode.factory.shardnet.near'

# check current validators
for i in res['result']['current_validators']:
    if i['account_id'] == staking_pool:
        print(i)
    else:
        continue

# check reason for kickout
for i in res['result']['prev_epoch_kickout']:
    if i['account_id'] == staking_pool:
        print(i)
    else:
        continue
  • Result example:

{'account_id': 'senseinode.factory.shardnet.near', 'is_slashed': False, 'num_expected_blocks': 15, 'num_expected_chunks': 37, 'num_produced_blocks': 14, 'num_produced_chunks': 34, 'public_key': 'ed25519:EfTpUmWR369JqZVf7UnrFsyQVXQ3fhFvNqbhMiDZEGU2', 'shards': [0], 'stake': '2309034326111880772000000000'}

  • For a staking pool in the current validator set you must make sure that num_expected_blocks and num_expected_chunks match the num_produced_blocks ad num_produced_chunks

Other Tools

Contributing

  • Contributions are welcome. Feel free to suggest improvements!

Made with ❤️ by Sensei Team

About

Near's Blockchain Node!

Resources

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •