logoDeveloper Hub

On Avalanche Mainnet

Deploy an Avalanche L1 to Avalanche Mainnet

Deploying an Avalanche L1 to Mainnet has many risks. Doing so safely requires a laser focus on security. This tutorial does its best to point out common pitfalls, but there may be other risks not discussed here.

This tutorial is an educational resource and provides no guarantees that following it results in a secure deployment. Additionally, this tutorial takes some shortcuts that aid the understanding of the deployment process at the expense of security. The text highlights these shortcuts and they shouldn't be used for a production deployment.

After managing a successful Avalanche L1 deployment on the Fuji Testnet, you're ready to deploy your Avalanche L1 on Mainnet. If you haven't done so, first Deploy an Avalanche L1 on Testnet.

This tutorial shows how to do the following on Mainnet.

  • Deploy an Avalanche L1.
  • Add a node as a validator to the Avalanche L1.
Note

All IDs in this article are for illustration purposes only. They are guaranteed to be different in your own run-through of this tutorial.

Prerequisites

Setting up Your Ledger

In the interest of security, all Avalanche-CLI Mainnet operations require the use of a connected Ledger device. You must unlock your Ledger and run the Avalanche App. See How to Use Ledger for help getting set up.

Ledger devices support TX signing for any address inside a sequence automatically generated by the device.

By default, Avalanche-CLI uses the first address of the derivation, and that address needs funds to issue the TXs to create the Avalanche L1 and add validators.

To get the first Mainnet address of your Ledger device, first make sure it is connected, unblocked, and running the Avalanche app. Then execute the key list command:

avalanche key list --ledger 0 --mainnet
+--------+---------+-------------------------+-----------------------------------------------+---------+---------+
|  KIND  |  NAME   |          CHAIN          |                    ADDRESS                    | BALANCE | NETWORK |
+--------+---------+-------------------------+-----------------------------------------------+---------+---------+
| ledger | index 0 | P-Chain (Bech32 format) | P-avax1ucykh6ls8thqpuwhg3vp8vvu6spg5e8tp8a25j |      11 | Mainnet |
+--------+---------+-------------------------+-----------------------------------------------+---------+---------+

The command prints the P-Chain address for Mainnet, P-avax1ucykh6ls8thqpuwhg3vp8vvu6spg5e8tp8a25j, and its balance.

Note

You can use the key list command to get any Ledger address in the derivation sequence by changing the index parameter from 0 to the one desired, or to a list of them (for example: 2, or 0,4,7). Also, you can ask for addresses on Mainnet with the --mainnet parameter, and local networks with the --local parameter.

Funding the Ledger

A new Ledger device has no funds on the addresses it controls. You'll need to send funds to it by exporting them from C-Chain to the P-Chain using Core web connected to Core extension.

You can load the Ledger's C-Chain address in Core extension, or load in a different private key to Core extension, and then connect to Core web .

You can move test funds from the C-Chain to the P-Chain by clicking Stake on Core web , then Cross-Chain Transfer (find more details on this tutorial).

Deploy the Avalanche L1

Note

To deploy the Avalanche L1, you will need some AVAX on the P-Chain.

For our Fuji example, we used our local machine as a bootstrap validator. However, since bootstrapping a node to Mainnet will take several hours, we will use an Avalanche node set up on an AWS server that is already bootstrapped to Mainnet for this example.

To check if the Avalanche node is done bootstrapping, ssh into the node and call info.isBootstrapped by copying and pasting the following command:

curl -X POST --data '{
    "jsonrpc":"2.0",
    "id"     :1,
    "method" :"info.isBootstrapped",
    "params": {
        "chain":"P"
    }
}' -H 'content-type:application/json;' 127.0.0.1:9650/ext/info

If this returns true, it means that the chain is bootstrapped and we will proceed to deploying our L1.

We will need to have the Avalanche node's NodeID, BLS public key and proof of possession. These can be obtained by ssh into the node itself and run the getNodeID API specified here

To deploy the new Avalanche L1, with your Ledger unlocked and running the Avalanche app, run:

avalanche blockchain deploy testblockchain

This is going to start a new prompt series.

Use the arrow keys to navigate:
? Choose a network to deploy on:
    Local Network
    Fuji
 Mainnet

This tutorial is about deploying to Mainnet, so navigate with the arrow keys to Mainnet and hit enter. The user is then asked to provide which private key to use for the deployment. Select a key to has P-Chain AVAX to pay for transaction fees.

 Mainnet
Deploying [testblockchain] to Mainnet

After that, CLI shows the Mainnet Ledger address used to fund the deployment:

Ledger address: P-avax1ucykh6ls8thqpuwhg3vp8vvu6spg5e8tp8a25j

Select No to using local machine as a bootstrap validator on the blockchain.

You can use your local machine as a bootstrap validator on the blockchain
This means that you don't have to to set up a remote server on a cloud service (e.g. AWS / GCP) to be a validator on the blockchain.
Use the arrow keys to navigate: ↓ ↑ → ←
? Do you want to use your local machine as a bootstrap validator?:
    Yes
  ▸ No

Enter 1 as the number of bootstrap validators we will be setting up.

 No
 How many bootstrap validators do you want to set up?: 1

Select Yes since we have already set up our Avalanche Node on AWS.

If you have set up your own Avalanche Nodes, you can provide the Node ID and BLS Key from those nodes in the next step.
Otherwise, we will generate new Node IDs and BLS Key for you.
Use the arrow keys to navigate:
? Have you set up your own Avalanche Nodes?:
 Yes
    No

Next, we will enter the node's Node-ID:

Getting info for bootstrap validator 1
 What is the NodeID of the node you want to add as bootstrap validator?:

And BLS public key and proof of possession:

Next, we need the public key and proof of possession of the node's BLS
Check https://docs.avax.network/api-reference/info-api#infogetnodeid for instructions on calling info.getNodeID API
✗ What is the node's BLS public key?:

Next, the CLI generates a CreateSubnet TX to create the Subnet and asks the user to sign it by using the Ledger.

*** Please sign Avalanche L1 creation hash on the ledger device ***

This activates a Please review window on the Ledger. Navigate to the Ledger's APPROVE window by using the Ledger's right button, and then authorize the request by pressing both left and right buttons.

If the Ledger doesn't have enough funds, the user may see an error message:

*** Please sign Avalanche L1 creation hash on the ledger device ***
Error: insufficient funds: provided UTXOs need 1000000000 more units of asset "U8iRqJoiJm8xZHAacmvYyZVwqQx6uDNtQeP3CQ6fcgQk3JqnK"

If successful, the CLI next asks you to sign a CreateChain Tx. Once CreateChain Tx is signed, it will then ask you to sign ConvertSubnetToL1 Tx.

Well done. You have just created your own Avalanche L1 on Mainnet.

You will be able to see information on the deployed L1 at the end of avalanche blockchain deploy command:

+--------------------+----------------------------------------------------+
| DEPLOYMENT RESULTS |                                                    |
+--------------------+----------------------------------------------------+
| Chain Name         | testblockchain                                     |
+--------------------+----------------------------------------------------+
| Subnet ID          | 2cNuyBhvAd4jH5bFSGndezhB66Z4UHYAsLCMGoCpvhXVhrZfgd |
+--------------------+----------------------------------------------------+
| VM ID              | qcvkEX1zWSz7PtGd7CKvPRBqLVTzA7qyMPvkh5NMDWkuhrcCu  |
+--------------------+----------------------------------------------------+
| Blockchain ID      | 2U7vNdB78xTiN6QtZ9aetfKoGtQhfeEPQG6QZC8bpq8QMf4cDx |
+--------------------+                                                    +
| P-Chain TXID       |                                                    |
+--------------------+----------------------------------------------------+

To get your new Avalanche L1 information, there are two options:

  • Call avalanche blockchain describe command or
  • Visit the Avalanche L1 Explorer. The search best works by blockchain ID, so in this example, enter 2U7vNdB78xTiN6QtZ9aetfKoGtQhfeEPQG6QZC8bpq8QMf4cDx into the search box and you should see your shiny new blockchain information.

Add a Validator

Before proceeding to add a validator to our Avalanche L1, we will need to have the validator's NodeID, BLS public key and proof of possession. These can be obtained by ssh into the node itself and run the getNodeID API specified here

To add a validator to an Avalanche L1, the owner of the key that acts as the controller of ValidatorManager contract specified in avalanche blockchain create command above run:

avalanche blockchain addValidator testblockchain

Choose Mainnet:

Use the arrow keys to navigate:
? Choose a network to deploy on:
 Mainnet

The CLI will show the Ledger address that will be used to pay for add validator tx:

Ledger address: P-avax1ucykh6ls8thqpuwhg3vp8vvu6spg5e8tp8a25j

Now enter the NodeID of the new validator to be added.

What is the NodeID of the validator you'd like to whitelist?: NodeID-BFa1paAAAAAAAAAAAAAAAAAAAAQGjPhUy

Next, enter the node's BLS public key and proof of possession.

Now, enter the amount of AVAX that you would like to allocate to the new validator.

The validator's balance is used to pay for continuous fee to the P-Chain. When this Balance reaches 0, the validator will be considered inactive and will no longer participate in validating the L1.

1 AVAX should last the validator about a month.

What balance would you like to assign to the validator (in AVAX)?: 1

Sign the addValidatorTx with your Ledger:

*** Please sign add validator hash on the ledger device ***

This activates a Please review window on the Ledger. Navigate to the Ledger's APPROVE window by using the Ledger's right button, and then authorize the request by pressing both left and right buttons.

This might take a couple of seconds. After, it prints:

Transaction successful, transaction ID: r3tJ4Wr2CWA8AaticmFrKdKgAs5AhW2wwWTaQHRBZKwJhsXzb

This means the node is now a validator on the given Avalanche L1 on Mainnet!

Going Live

For the safety of your validators, you should setup dedicated API nodes to process transactions, but for test purposes, you can issue transactions directly to one of your validator's RPC interface.

Last updated on

On this page

Edit on Github