Polygon Supernet installation

Steps to install and run a Polygon Supernet over Polygon’s Mumbai testnet blockchain using Polygon Edge v1.0.0-rc1.

Official minimum requirements

Table of Contents

Step 1. Create my Google Cloud environment

I’m testing on a Debian 12 (bookworm) on Google Cloud, but steps will be similar on most Linux systems. Specifically:

  • Region: europe-west1-b
  • Zone: europe-west1-b
  • Machine configuration: e2-medium (2 vCPU, 4GB memory)
  • Boot disk: Debian GNU/Linux 12 (bookworm), SSD persistent disk (10GB)

For Google Cloud it can come in handy to have gCloud CLI installed on your system. Once installed run gcloud init to login with your credentials, pick your cloud project to use and configure a default Compute Region and Zone.

You can then create an instance over the web on over the command line:

gcloud compute instances create polygon-instance-1 \
    --project=polygon-060623 \
    --zone=europe-west1-b \
    --machine-type=e2-medium \
    --network-interface=network-tier=PREMIUM,stack-type=IPV4_ONLY,subnet=default \
    --maintenance-policy=MIGRATE \
    --provisioning-model=STANDARD \
    --service-account=723590745892-compute@developer.gserviceaccount.com \
    --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append \
    --create-disk=auto-delete=yes,boot=yes,device-name=instance-2,image=projects/debian-cloud/global/images/debian-12-bookworm-v20230609,mode=rw,size=10,type=projects/polygon-060623/zones/europe-west1-b/diskTypes/pd-ssd \
    --no-shielded-secure-boot \
    --shielded-vtpm \
    --shielded-integrity-monitoring \
    --labels=goog-ec-src=vm_add-gcloud \
    --reservation-affinity=any

Output in this case is:

NAME                ZONE            MACHINE_TYPE  PREEMPTIBLE  INTERNAL_IP  EXTERNAL_IP    STATUS
polygon-instance-1  europe-west1-b  e2-medium                  10.132.0.4   34.140.114.17  RUNNING

Once your VM is created you can login with gcloud compute ssh myinstancename

Step 2. Update system and install required dependencies

sudo apt update && sudo apt upgrade -y
sudo apt install -y golang git

Step 3. Download and build

Clone the repository and select the latest release. In my case today its v1.0.0-rc1

git clone https://github.com/0xPolygon/polygon-edge.git
cd polygon-edge/
git checkout v1.0.0-rc1

Build from source

go build -o polygon-edge .

Step 4. Generate Secrets

Generate New Account Secrets

For a production environment we will need a secrets backend, meaning the secret should not be stored in the local filesystem. For this testing example we can store them locally with the --insecure flag

./polygon-edge polybft-secrets --insecure --data-dir mycoolchain --num 3

I choose the name mycoolchain but you can enter any other value instead. This will generate 3 folders mycoolchain1, mycoolchain2 and mycoolchain3 and 3 secrets. Each secret having a public key (address), BLS Public key and a Node ID, which we will need for later

Output for each secret should be something similar to this

Public key (address) = 0x9eE89ddC7c4715307b84dba6C7Af30C023750395
BLS Public key       = 02a8db3ab127c1f0f24515dab4dd3a80ac407611b0b04beaf21ffe1b088e6c072125ba807fe94d39496b19be9eec88ca5cf71ce669816d5a1eaddf5d03976bc400d00932705a5fb9c1a0ba7d632510b4560aa66a3b489ad20aac3470a7b864c5294278e7bbe1a7c35a678324d1d4be48028291380c93e7badf02c3174948c145
Node ID              = 16Uiu2HAmJiyAHwexPHhDweYiioo8fhs3ntZK4A9MovACzQu3ur5L

You can retrieve later with the following command:

./polygon-edge polybft-secrets --data-dir mycoolchain1 --insecure --private

Step 5. Configure new Child Chain

To generate the new chain we will use the genesis command. A full description of this command can be found by running ./polygon-edge genesis --help.

Specific values should depend on your particular requirements, however the following ones and particular important that we should be aware about, even if we use the default values:

Flag Default Value Description
block-gas-limit 5242880 Maximum amount of gas used by all transactions
block-time 2 seconds Predefined period which determines block creation frequency
epoch-size 100000 epoch size for the chain
validators-prefix test-chain- Folder prefix names for polybft validator secrets (mycoolchain in this example)
validators-path ./ root path cotaining polybft validators secrets
consensus polybft consensus protocol to be used
reward-wallet   configuration of reward wallet in format address:amount
transactions-allow-list-admin   list of addresses to use as admin accounts in the transactions allow list
transactions-allow-list-enabled   list of addresses to enable by default in the transactions allow list
premine balance of 1000000000000000000000000 the premined accounts and balances (format: address:balance)
native-token-config   configuration of the native token in format name:symbol:decimals count:mintable

Note: The epoch-size is the number of blocks where the validators remain constant. So, with an epoch-size of 100,000 and block-time of 2 seconds, it will be aproximatly 55 hours.

They are two configuration options here:

  • Single-host Validator
  • Multi-host Validator

Step 5.1. Single-host Validator

I’m going to enter the Public key (address) of my first account I just created as a reward-wallet, transactions-allos-list-admin and transactions-allos-list enabled.

I’ll add a second account, as well as, for the transactions-allow-list-admin and transactions-allow-list-enabled.

So command looks like this (you will need to enter your own public keys):

./polygon-edge genesis \
  --validators-prefix mycoolchain \
  --reward-wallet 0xB9C3AB496F74d48340DD2A39C4a3e8eA0189e657:3000000 \
  --transactions-allow-list-admin 0xB9C3AB496F74d48340DD2A39C4a3e8eA0189e657, 0xa25D637B9Af0fBB142A6f5FD9E549A0181A1C96D \
  --transactions-allow-list-enabled 0xB9C3AB496F74d48340DD2A39C4a3e8eA0189e657, 0xa25D637B9Af0fBB142A6f5FD9E549A0181A1C96D

The above command will create a chain with the following configuration:

  • Setup the default block-gas-limit of 5242880
  • Setup the default block-time of 2 seconds
  • Setup the default epoch-size of 10000 blocks
  • Setup the default validators-path of “./”
  • Used the default consensus protocol of polybft.
  • Specify a specific reward-wallet address and amount
  • Specify the list of address to use ad admin accounts
  • Specify the list of addresses to enable by default in the transactions allow list

Optionally I could create my own token by adding something like this in the same command:

  --premine 0xB9C3AB496F74d48340DD2A39C4a3e8eA0189e657:200000 \
  --native-token-config "Crums:CRM:2:true" 

The command will output [GENESIS SUCCESS] and create a genesis.json file. You can easily delete the genesis.json file and rerun the command if you want to change anything or play around with the config parameters.

Step 6 Configure Rootchain

Step 6.1 Deploy rootchain contracts

Run:

./polygon-edge rootchain server

This command requires Docker. To install it in Debian, follow these steps. Recommended to also follow these steps to manage docker as a non-root-user.

Step 6.2. Polygon-CLI (Optional)

A useful tool is polygon-cli.

# Clone polygon-cli repo and enter its folder
git clone https://github.com/maticnetwork/polygon-cli
cd polygon-cli

# Install polygon-cli requirementes
sudo apt install make jq bc

# Make polygon-cli
make install

You can also use polygoncli to monitor your chain:

polycli monitor http://127.0.0.1:8545

Step 6.3. Add Funds

Now we need to deploy the stakemanager contract but in order to do so we need funds.

To initialice the contracts on the rootchain we need funds to pay for the gas.

./polygon-edge rootchain fund --addresses 0x77C1eedFf656477462ce16084fE5Dc7F8a2507B9 --amounts 1000000000000000000

Step 6-4 Deploy StakeManager contract

We will now deploy the rootchain contract using the command ./polygon-edge polybft stake-manager-deploy. Details of the command can be found with:

./polygon-edge polybft stake-manager-deploy --help

To run this command you will need a private key (can be retrieved with the command above of polybft-secrets).

./polygon-edge polybft stake-manager-deploy \
  --private-key <hex_encoded_rootchain_account_private_key> \
  --jsonrpc http://127.0.0.1:8545] \
  [--genesis ./genesis.json] \
  [--stake-token 0xaddressOfStakeToken] \
  [--test]

Output will be similar to this

[STAKEMANAGER - DEPLOY] Successfully deployed StakeManager contract

[STAKEMANAGER - DEPLOY] StakeManager contract is initialized

In the logs of the chain we will see something similar to this:

INFO [06-26|11:59:09.797] Submitted contract creation              hash=0xeace5f9bed73b471d6309d7ff7827b0daae9791bd91d4de46eef54dc17a462cd from=0x77C1eedFf656477462ce16084fE5Dc7F8a2507B9 nonce=0 contract=0x496933cc73D80fbcac09d5d7141b981DA3823B4f value=0

This will give us the contract address we just created. In this example its ´0x496933cc73D80fbcac09d5d7141b981DA3823B4f´.

An easier way to get this is address is with the following command:

cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeManagerAddr'

Obtain the stakeToken:

cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeTokenAddr'

Obtain the Supernet Manager Address:

cat genesis.json | jq -r '.params.engine.polybft.bridge.customSupernetManagerAddr'

Obtain the Supernet ID:

cat genesis.json | jq -r '.params.engine.polybft.supernetID'

Step 6.5 Deploy Rootchain Contract

Nonworking code:

./polygon-edge rootchain deploy \
  --genesis ./genesis.json \
  --json-rpc http://127.0.0.1:8545 \
  --test

Testing:

./polygon-edge rootchain deploy --test \
  --stake-manager 0x496933cc73D80fbcac09d5d7141b981DA3823B4f \
  --stake-token 0x0000000000000000000000000000000000000000

Getting the variable I need directly from my genesis.json file:

./polygon-edge rootchain deploy --test \
  --stake-manager $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeManagerAddr') \
  --stake-token $(cat genesis.json | jq -r '.params.engine.polybft.bridge.stakeTokenAddr')