Turn Node Into Validator
This tutorial will show you how to add a node to the validator set of Primary Network on Avalanche.
Introduction
The Primary Network is inherent to the Avalanche platform and validates Avalanche's built-in blockchains. In this tutorial, we'll add a node to the Primary Network on Avalanche.
The P-Chain manages metadata on Avalanche. This includes tracking which nodes are in which Subnets, which blockchains exist, and which Subnets are validating which blockchains. To add a validator, we'll issue transactions to the P-Chain.
Note that once you issue the transaction to add a node as a validator, there is no way to change the parameters. You can't remove your stake early or change the stake amount, node ID, or reward address. Please make sure you're using the correct values in the API calls below. If you're not sure, feel free to join our Discord to ask questions.
Requirements
You've completed Run an Avalanche Node and are familiar with Avalanche's architecture. In this tutorial, we use AvalancheJS and Avalanche's Postman collection to help us make API calls.
In order to ensure your node is well-connected, make sure that your node can
receive and send TCP traffic on the staking port (9651
by default) and your node
has a public IP address(it's optional to set --public-ip=[YOUR NODE'S PUBLIC IP HERE]
when executing the AvalancheGo binary, as by default, the node will attempt to perform
NAT traversal to get the node's IP according to its router). Failing to do either of
these may jeopardize your staking reward.
Add a Validator with Core extension
First, we show you how to add your node as a validator by using Core web.
Retrieve the Node ID, the BLS signature and the BLS key
Get this info by calling info.getNodeID
:
The response has your node's ID, the BLS key (public key) and the BLS signature (proof of possession):
Add as a Validator
Connect Core extension to Core web, and go the 'Staking' tab. Here, choose 'Validate' from the menu.
Fill out the staking parameters. They are explained in more detail in this doc. When you've
filled in all the staking parameters and double-checked them, click Submit Validation
. Make sure the staking period is at
least 2 weeks, the delegation fee rate is at least 2%, and you're staking at
least 2,000 AVAX on Mainnet (1 AVAX on Fuji Testnet). A full guide about this can be found
here.
You should see a success message, and your balance should be updated.
Go back to the Stake
tab, and you'll see here an overview of your validation,
with information like the amount staked, staking time, and more.
Calling
platform.getPendingValidators
verifies that your transaction was accepted. Note that this API call should be
made before your node's validation start time, otherwise, the return will not
include your node's id as it is no longer pending.
You can also call
platform.getCurrentValidators
to check that your node's id is included in the response.
That's it!
Add a Validator with AvalancheJS
We can also add a node to the validator set using AvalancheJS.
Install AvalancheJS
To use AvalancheJS, you can clone the repo:
The repository cloning method used is HTTPS, but SSH can be used too:
git clone git@github.com:ava-labs/avalanchejs.git
You can find more about SSH and how to use it here.
or add it to an existing project:
For this tutorial we will use ts-node
to run the example scripts directly from an AvalancheJS directory.
Fuji Workflow
In this section, we will use Fuji Testnet to show how to add a node to the validator set.
Open your AvalancheJS directory and select the
examples/p-chain
folder to view the source code for the examples scripts.
We will use the
validate.ts
script to add a validator.
Add Necessary Environment Variables
Locate the .env.example
file at the root of AvalancheJS, and remove .example
from the title. Now, this will be the .env
file for global variables.
Add the private key and the P-Chain address associated with it.
The API URL is already set to Fuji (https://api.avax-test.network/
).
Retrieve the Node ID, the BLS signature and the BLS key
Get this info by calling info.getNodeID
:
The response has your node's ID, the BLS key (public key) and the BLS signature (proof of possession):
Fill in the Node ID, the BLS signature and the BLS key
After retrieving this data, go to examples/p-chain/validate.ts
.
Replace the nodeID
, blsPublicKey
and blsSignature
with your
own node's values.
Settings for Validation
Next we need to specify the node's validation period and delegation fee.
Validation Period
The validation period is set by default to 21 days, the start date being the date and time the transaction is issued. The start date cannot be modified.
The end date can be adjusted in the code.
Let's say we want the validation period to end after 50 days.
You can achieve this by adding the number of desired days to
endTime.getDate()
, in this case 50
.
Now let's say you want the staking period to end on a specific date and time, for example May 15, 2024, at 11:20 AM. It can be achieved as shown in the code below.
Delegation Fee Rate
Avalanche allows for delegation of stake. This parameter is the percent fee this
validator charges when others delegate stake to them. For example, if
delegationFeeRate
is 10
and someone delegates to this validator, then when
the delegation period is over, 10% of the reward goes to the validator and the
rest goes to the delegator, if this node meets the validation reward
requirements.
The delegation fee on AvalancheJS is set 20
. To change this, you need
to provide the desired fee percent as a parameter to newAddPermissionlessValidatorTx
,
which is by default 1e4 * 20
.
For example, if you'd want it to be 10
, the updated code would look like this:
Stake Amount
Set the amount being locked for validation when calling
newAddPermissionlessValidatorTx
by replacing weight
with a number
in the unit of nAVAX. For example, 2 AVAX
would be 2e9 nAVAX
.
Execute the Code
Now that we have made all of the necessary changes to the example script, it's time to add a validator to the Fuji Network.
Run the command:
The response:
We can check the transaction's status by running the example script with
platform.getTxStatus
or looking up the validator directly on the
explorer.
Mainnet Workflow
The Fuji workflow above can be adapted to Mainnet with the following modifications:
AVAX_PUBLIC_URL
should behttps://api.avax.network/
.P_CHAIN_ADDRESS
should be the Mainnet P-Chain address.- Set the correct amount to stake.
- The
blsPublicKey
,blsSignature
andnodeID
need to be the ones for your Mainnet Node.
Last updated on