Create Publication

We are looking for publications that demonstrate building dApps or smart contracts!
See the full list of Gitcoin bounties that are eligible for rewards.

Tutorial Thumbnail
Beginner · 30 minutes

Create A Private Network

Often creating a private network is desirable for developers. This allows simulating a multi node network contained on one computer. The network can be configured with multiple accounts and tokens distributed as the developer desires. Algorand’s goal utility supports commands to create, start, stop and delete private networks. This tutorial describes the process of creating a private network.

Requirements

Background

Before starting this tutorial, the goal binaries must be installed. See Installing a Node for more information on installing a node, which includes the goal binaries. Alternatively, the binaries can be installed without actually installing a node by getting the updater as described on the Installing a Node and then running the following command.

./updater ver get -c stable -o algorand-binaries.tar.gz

The binaries can then be unzipped and used to create a private network.

Network Template Overview

Before creating a private network a template needs to be created which describes how the network and wallets should be configured. Wallets have three properties, Name, Stake and Online. The wallet stake is specified in percent, and the percent should total 100%. Fractional percentages like 0.01 are allowed. Online is set to true or false and specifies whether the account is marked online. See Participate in Consensus for more details on online vs offline accounts.

Nodes can be configured with the Name, IsRelay, and Wallets properties. The Name property allows you to name each of the nodes. When a network is created locally, this name is used for the directory where the node files reside. IsRelay indicates the node is intended to be a relay - there must be at least one relay included in any network. Non-relay nodes will connect to the nodes marked as relays. The Wallets property specifies which wallets are assigned to each node. Each wallet entry has an additional ParticipationOnly property. This property indicates the wallet only has access to participation keys - not rootkeys. This means that the wallet is set up on the node to participate in consensus but no signing of transactions can occur on that node with the specific wallet. The default behavior is for ParticipationOnly to be false allowing participation for online accounts and signing of transactions.

Steps

1. Create Network Template

A Network Template is described in JSON format and contains the fields shown below.

{
    "Genesis": {
        "NetworkName": "",
        "Wallets": [
            {
                "Name": "Wallet1",
                "Stake": 50,
                "Online": true
            },
            {
                "Name": "Wallet2",
                "Stake": 40,
                "Online": true
            },
            {
                "Name": "Wallet3",
                "Stake": 10,
                "Online": false
            }
        ]
    },
    "Nodes": [
        {
            "Name": "Primary",
            "IsRelay": true,
            "Wallets": [
                {
                    "Name": "Wallet1",
                    "ParticipationOnly": false
                }
            ]
        },
        {
            "Name": "Node",
            "Wallets": [
                {
                    "Name": "Wallet2",
                    "ParticipationOnly": false
                },
                {
                    "Name": "Wallet3",
                    "ParticipationOnly": false
                }
            ]
        }
    ]
}

Open a text editor and copy and paste the above template. Save the template as my_network_template.json to the directory containing the goal binaries.

Info

If creating a private network with BetaNet binaries you will need to add one addtional field (ConsensusProtocol) to the network template. This property should be placed directly below the network name.

"NetworkName": "", "ConsensusProtocol": "future",

2. Create Network

./goal network create -r ~/net1 -n private -t my_network_template.json

This will create the net1 folder in the home directory. This directory can be set to a different location by using the -r option. The -n option specifies the name of the network and the -t option specifies the network template created in step 1. within the ~/net1 directory, rootkeys for all wallets are created and a directory for each node in the network are also created. In this template the folders Primary and Node are created.

3. Start the Network

The network can be started by running the following goal command.

goal network start -r ~/net1

An algod process will be started for every node described in the tempate. This can be checked by running the following command.

ps aux | grep algod

4. Check the Network Status

goal network status -r ~/net1

This will list the status of each node in the network. Output similar to the following will be shown.

[Primary]
Last committed block: 46
Time since last block: 3.5s
Sync Time: 0.0s
Last consensus protocol: https://github.com/algorandfoundation/specs/tree/4a9db6a25595c6fd097cf9cc137cc83027787eaa
Next consensus protocol: https://github.com/algorandfoundation/specs/tree/4a9db6a25595c6fd097cf9cc137cc83027787eaa
Round for next consensus protocol: 47
Next consensus protocol supported: true
Has Synced Since Startup: false

[Node]
Last committed block: 46
Time since last block: 3.5s
Sync Time: 0.0s
Last consensus protocol: https://github.com/algorandfoundation/specs/tree/4a9db6a25595c6fd097cf9cc137cc83027787eaa
Next consensus protocol: https://github.com/algorandfoundation/specs/tree/4a9db6a25595c6fd097cf9cc137cc83027787eaa
Round for next consensus protocol: 47
Next consensus protocol supported: true
Has Synced Since Startup: false

5. List Accounts on both Nodes

To see the accounts created by the network template on each node in the private network you can use standard goal account list commands.

./goal account list -d ~/net1/Primary
[Accounts on Primary Node Listed]
./goal account list -d ~/net1/Node
[Accounts on Secondary Node Listed]

The primary thing to note is that you must specify the data directory to point the to the private network’s specific node directory.

6. Stop the Private Network

The private network can be stopped by using the network stop command.

goal network stop -r ~/net1

7. Delete the Private Network

The private network can be deleted by using the network delete command. If the network is running, it will automatically shutdown.

goal network delete -r ~/net1

This will delete the ~/net1 directory.