See any bugs? Let us know in the #algorand channel in the BEN Slack!
In this activity, you will learn how to build a private network on Algorand, create and manage new nodes and wallets, and even send multisignature transactions on your own private network.
Refer to the official Algorand documentation or post in the #algorand-channel if you are having any issues. Join BEN if you have not already done so.
You Will Need
An Algorand node comes with two main installations -> a binaries folder and a data folder.
Mac
mkdir ~/inst cd ~/inst
copy the installer from GitHub https://github.com/algorand/go-algorand-doc/blob/master/downloads/installers/darwin_amd64/install_master_darwin-amd64.tar.gz
tar -xf install_master_darwin-amd64.tar.gz ./update.sh -i -c stable -p ~/node -d ~/node/data -n
Mac users will find everything in their data folder. ./goal node start -d data ./goal node status -d data
Watch the node sync live with ./carpenter -d data
Linux DEB users will find the binaries in their /var/bin and the data in the /var/ folder. For DEB users
sudo apt-get update sudo apt-get install -y gnupg2 curl software-properties-common curl -O https://releases.algorand.com/key.pub sudo apt-key add key.pub sudo add-apt-repository "deb https://releases.algorand.com/deb/ stable main" sudo apt-get update sudo apt-get install -y algorand algod -v
Check that the node is running goal node status -d /var/lib/algorand
Refer to https://developer.algorand.org/docs/introduction-installing-node if instructions are unclear.
Now that you are running your own Algorand node, we will use the goal network set of commands to create a private network, complete with a set of nodes. Refer to the instructions from the “Creating a Private Network” tutorial by Algorand to set up your very own private Algorand network.
First, create a folder called "Algorand" on your computer to store all of your working files. Open the terminal from within this folder.
Second we will design your new private network. Create a new file called my-network.json. This network will have two nodes, Primary and Node2.
{ "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": "Node2", "Wallets": [ { "Name": "Wallet2", "ParticipationOnly": false }, { "Name": "Wallet3", "ParticipationOnly": false } ] } ] }
Now we will create our new network and call it net1. Run the following command from within your Algorand folder. Mac users should use ./goal network instead of goal network
goal network create -r net1 -n private -t my-network.json
This creates a folder called "net1" in your current folder using the my-network.json file.
Now, start your private network by running.
.goal network start -r net1
You can see all of your running nodes by running:
goal network status -r net1
To see the info of a specific node use
.goal node status -d net1/Primary
Use -r for the root directory, use -d for a particular data directory (Node1, Node2).
See your new network live through the Primary Node or Node2!
carpenter -d net1/Primary
Now that you have your own private network, we will create a new wallet called "my-wallet" on the primary node. Refer to the documentation “Creating a New Wallet” if you are having trouble.
Run the following command.
goal wallet new MyWallet -d net1/Primary
You will be asked to set up a password for you new wallet. You will also get the chance to see your seed phrase.
You can see all your wallets with
goal wallet list -d net1/Primary
You should see an original unencrypted-default-wallet alongside your newly created wallet.
################################################## Wallet: mywallet ID: b455cf325e01ee55aa4e5e94e4c0c6b5 ################################################## Wallet: unencrypted-default-wallet ID: 952f9b24fe8afc1d32ab077b4bd54306 ##################################################
Each wallet can store accounts with addresses. Create a new account on your wallet MyWallet. goal account new -w my-wallet -d net1/Primary
View the list of your accounts
goal account list -w my-wallet -d net1/Primary
You should see something like
[offline] Unnamed-0 SLAXXYAYHEZ7PPRYGVSRSVCUNODXNHYZ25PMUUKLQB4NL3PU5QRYJL3WZA 0 microAlgos *Default`
Using the same command, view the list of your accounts in the unencrypted default wallet
goal account list -w unencrypted-default-wallet -d net1/Primary
You should see something like
[online] KPFUKS3ITJXZJG3BMFEV5UV6PWAY5P2VZFP4PTTWKREFW6WM5U3GN5TEVM KPFUKS3ITJXZJG3BMFEV5UV6PWAY5P2VZFP4PTTWKREFW6WM5U3GN5TEVM 5000010000000000 microAlgos
Now you will create a participation key for your new account. As covered in the protocol overview guide, participation keys are necessary for an account to participate in consensus. Refer to “Creating a New Account and Participation Key” tutorial by Algorand for extra help.
Use the following command with the address for your account.
goal account addpartkey -a [NewlyCreatedAccount] --roundFirstValid 50 --roundLastValid 4000 -d net1/Primary
goal account addpartkey -a NewlyCreatedAccount --roundFirstVaild 50 --roundLastValid 400 The current block number must be in the range of roundFirstValid and roundLastValid. -d net1/Primary
If it works, you should get a message Participation key generation successful
Next, your account needs algos. Send algos from the default account in your unencrypted-default-wallet to your new account in your new wallet.
goal clerk send -a 102000 -f [ExistingAccount] -t [NewlyCreatedAccount] -d net1/Primary -w unencrypted-default-wallet
goal clerk send
-a 102000 the amount to be send
-f [ExistingAccount]
-t [NewlyCreatedAccount]
-d net1/Primary
-w unencrypted-default-wallet the wallet you will need to sign the transaction with (usually the sender)
You should receive a message like
Sent 100000 MicroAlgos from account 67ZBWYNUXGAYHTI6M7VCS7TEHCQCHTRNSPCW6XNE4NU3F4CN44HVPX35SU to address YINP744EV7LPNOHD6CNXDWIYVBWS7YGBUEXIGPAS3NF7R4CDU2QLU3FX3Q, transaction ID: KCYEVLHFI2C756LEPHXK3H6CXOB7KYHZ5YIRNQDX74HY7YC2VMMQ. Fee set to 1000 Transaction KCYEVLHFI2C756LEPHXK3H6CXOB7KYHZ5YIRNQDX74HY7YC2VMMQ still pending as of round 138 Transaction KCYEVLHFI2C756LEPHXK3H6CXOB7KYHZ5YIRNQDX74HY7YC2VMMQ committed in round 140
Finally, turn the account on for it to start participating in conesnsus
goal account changeonlinestatus -a [NewlyCreatedAccount] -o=true -w mywallet -d net1/Primary
You should receive the message
Transaction id for status change transaction: HJMMI3VK6Y4S6Y2PWR65DMPWGLFWN2ILESTIDOWUJ33JGD22V7AA Transaction HJMMI3VK6Y4S6Y2PWR65DMPWGLFWN2ILESTIDOWUJ33JGD22V7AA still pending as of round 490 Transaction HJMMI3VK6Y4S6Y2PWR65DMPWGLFWN2ILESTIDOWUJ33JGD22V7AA committed in round 492
Instead of immediately sending a transaction, you can write a raw unsigned or signed transaction and submit it to the blockchain using the algod REST endpoint on your node. Refer to the instructions from the “Write a Raw Transaction and Post to algod REST Server.” tutorial by Algorand.
goal clerk send -s -o raw.tx -a 102000 -f [FromAccount] -t [ToAccount] -d net1/Primary -w unencrypted-default-wallet
goal clerk send -s -o raw.tx -o dumps the transaction to the file "raw.tx". -s indicateds that the transaction should be signed. -a 102000 the amount -f [FromAccount] the account you are sending from -t [ToAccount] the account to send it to -d net1/Primary data directory -w unencrypted-default-wallet the signing wallet
You will see the raw.tx file in your folder now.
To submit the transaction to the blockchain, run
curl -s -X POST --data-binary "@raw.tx" -H "X-Algo-API-Token: $(cat net1/Primary/algod.token)" "http://$(cat net1/Primary/algod.net)/v1/transactions"
Multisignature account require signatures from multiple accounts before processing a transaction. Refer to the instructions from “Creating a Multisignature Account” by Algorand.
Create a new multisign wallet using the following command.
goal account multisig new [FirstAccount] [SecondAccount] -T 2 -d net1/Primary -w mywallet
-T [Number] the threshold for the number of signatures required
Now look at your accounts and you will see the new multisig account.
goal account list -d net1/Primary -w my-wallet
Result:
[offline] Unnamed-1 U37KAEBT4NXIGDB2KZPDNQHNPAFYHCLSZEDIU5BJEGRREWRPFFP7ZCGYSM 0 microAlgos [2/2 multisig]
Send a transaction as before to load the new account with microalgos.
goal clerk send -a 200000 -f [AccountWithTokens] -t [NewMultiSignatureAccount] -d net/Primary -w unencrypted-default-wallet
Result:
[offline] Unnamed-1 U37KAEBT4NXIGDB2KZPDNQHNPAFYHCLSZEDIU5BJEGRREWRPFFP7ZCGYSM 200000 microAlgos [2/2 multisig]
Now for a multisignature transaction. Create a new transaction and output it to multi.tx.
goal clerk send -a 90000 -f [NewMultiSignatureAccount] -t [AnyOtherAccount] -o multi.tx -d net1/Primary
For the transaction to go through, you will need to sign your transaction with both accounts. If the accounts were on different wallets, you would need the passwords of both wallets.
goal clerk multisig sign -t mutli.tx -a [FirstAccount] -d net1/Primary -w [Wallet]goal clerk multisig sign -t multi.tx -a [SecondAccount] -d net1/Primary -w [Wallet]
Finally, now that the signatures are completed you can either use the REST API or the goal clerk rawsend command to submit the transaction.
goal clerk rawsend -f multi.tx -d net1/Primary
Result:
Raw transaction ID J3GG7FW5O6RADYYUNL4RFQ2BXAS7SLRSU6ZVSRQKYGZQA62BGY7A issued Transaction J3GG7FW5O6RADYYUNL4RFQ2BXAS7SLRSU6ZVSRQKYGZQA62BGY7A still pending as of round 820 Transaction J3GG7FW5O6RADYYUNL4RFQ2BXAS7SLRSU6ZVSRQKYGZQA62BGY7A committed in round 822
To finish off, you can close out and delete your private network.
goal network delete -r net1