Deploy Mainnet Staking Pool
Deploying a node on mainnet is similar to deploying one on testnet
and requires the following steps:
- Create
mainnetwallet. - Build
mainnetvalidator node daemon. - Initialize the node.
- Deploy
mainnetstaking pool. - Run the validator node.
1. Create mainnet wallet​
If you don’t have a NEAR account, first go to NEAR Wallet and create one.
2. Build mainnet validator node daemon​
To build the validator first clone the nearcore
repository:
git clone https://github.com/near/nearcore.git
Once that’s done, figure out the most recent stable
release. Stable releases
are ones without -rc.<number> suffix (‘rc’ stands for ‘release
candidate’). This can be done automatically as follows:
NEAR_RELEASE_VERSION=$(curl -s https://api.github.com/repos/near/nearcore/releases/latest |
grep '"tag_name"' | cut -d '"' -f 4)
echo "${NEAR_RELEASE_VERSION:?}"
Now, go to the cloned repository’s root directory, check out the code corresponding to the latest stable release and build the executable. Each nearcore release is a git tag:
cd nearcore
git checkout "tags/${NEAR_RELEASE_VERSION:?}" && make neard
make neard builds with the release profile, which already enables
full optimization. The executable is at ./target/release/neard.
3. Initialize the node​
Once the daemon executable is built it’s time to initialize the node.
The reference validator config.json has no boot nodes. Follow Fetch boot nodes with CHAIN_ID=mainnet to set BOOT_NODES, then return here and continue in the same shell.
Then initialize the node with the reference validator config and the boot nodes:
./target/release/neard init --chain-id=mainnet \
--account-id="<POOL_ID>.poolv1.near" \
--download-config validator \
--boot-nodes "${BOOT_NODES:?}"
--download-config validator downloads the reference validator
config.json. Without it, neard init writes a default config that
tracks all shards. On mainnet, a node that tracks all shards stops at
startup while its account is a validator in the current epoch.
<POOL_ID> is the name you want to use for your staking pool. Note
that at this point the <POOL_ID>.poolv1.near account doesn’t yet
exist. We’re going to create it in the next step.
This command will create a ~/.near/validator_key.json file which
will contain validator’s private key. neard init creates this file
only when --account-id is given. It also creates
~/.near/node_key.json, which holds the node’s network key. Do not
use the key from node_key.json for staking. It’s a good idea to back
up validator_key.json in a secure location. For now, read the
validator’s public key from this file:
grep public_key ~/.near/validator_key.json
4. Deploy mainnet Staking Pool​
You can deploy the staking pool with near-cli,
using the near call command:
near call poolv1.near create_staking_pool '{
"staking_pool_id": "<POOL_ID>",
"owner_id": "<OWNER_ID>",
"stake_public_key": "<VALIDATOR_KEY>",
"reward_fee_fraction": {"numerator": <X>, "denominator": <Y>}
}' --account_id <OWNER_ID> --amount 30 --gas 300000000000000
It will invoke the staking-pool-factory method from NEAR Core
Contracts, passing the
following parameters:
poolv1.nearis the staking pool factory,<POOL_ID>is the name of your validator (and the staking pool associated with it),<OWNER_ID>is the wallet that controls the pool (see owner-only methods for more information),<VALIDATOR_KEY>is the validator node public key read in the previous step from the~/.near/validator_key.jsonfile,{"numerator": <X>, "denominator": <Y>}sets the validator fees (for exampleX=10andY=100means 10%),--amount 30attaches 30 $NEAR to the transaction to pay the contract storage,--gas 300000000000000specifies the amount of gas for the transaction (optional).
Note that if your <POOL_ID> is ‘buildlinks’, the staking pool
factory will deploy a contract called ‘buildlinks.poolv1.near’, and
your node will appear in the Explorer as ‘buildlinks.poolv1.near’.
This corresponds to the account identifier used in the previous step.
5. Run the validator node​
Once the daemon is built, node is initialized and staking pool
created, the validator can be started. To make sure the node has been
set up correctly, check that ~/.near/config.json lists boot nodes and
tracks no shards:
jq '.network.boot_nodes, .tracked_shards_config' ~/.near/config.json
The first value must not be empty, and the second must be "NoShards".
A validator still tracks the shards it is assigned to. Your
config.json does not match the reference file byte for byte. This is
expected, because neard init adds the boot nodes and writes the file
again.
If everything is in order, start your node with the following command:
./target/release/neard run
After the node starts, check its log. The node logs Waiting for peers
until it is connected to at least consensus.min_num_peers peers (3 by
default). If the message does not go away, the node cannot connect to
enough peers. Check that network.boot_nodes in config.json is not
empty, and that the machine can reach those addresses.
You can start your node without the JSON RPC endpoint by running the
above command with an additional --disable-rpc flag. This reduces
resource use and attack vector by closing a listening port.