Algorand Consensus Protocol
Algorand Consensus Protocol
Algorand Consensus Protocol
all participants. It provides various unique features like ASAs, Atomic Transfers, Stateless & Stateful
Smart Contracts and much more.
How it works:
Algorand’s consensus protocol works by selecting a block proposer and a set of voting committees at
each block round, to propose a block and validate the proposal, respectively. The proposer and
committees are randomly chosen from the pool of all token holders (the accounts that hold algos), and
the likelihood of being chosen is proportional to the account’s stake in the network (i.e. how many algos
it has relative to the whole).
Detailed Explanation of Consensus
Functionalities in Algorand on Layer 1
Algorand provides a standalone daemon algorand-indexer that reads committed blocks from the
Algorand blockchain and maintains a local database of transactions and accounts that are searchable
and indexed.
Algorand provides three command-line utilities packaged with Algorand node software: goal,
kmd, and algokey.
goal is the primary tool for operating a node and it also contains functionality to manage keys,
sign and send transactions, create assets, and perform many of the same or similar functions that
are available in the SDKs. Although not required to build an application, developers who run
nodes may find it useful to achieve some level of fluency in goal as a complementary tool
during testing and validation. goal is required to setup more advanced testing environments
using private networks.
kmd is the CLI for the Algorand Key Management daemon and algokey is a standalone utility
for generating Algorand accounts and for signing transactions. It is often used as a lightweight
offline client for secure key signing.
Algorand Networks
Mainnet
Testnet
1. Sandbox
Sandbox:
The sandbox allows developers to create local, private networks. Moreover, we can quickly remove a
network, reset its state, or spin up a new network. The only requirement for using the Algorand sandbox
is installing Docker and Docker-Compose.
Ubuntu and macOS
cd sandbox
./sandbox up
This will run the sandbox shell script with the default configuration.
Run the test command for examples of how to interact with the environment:
./sandbox test
# Available accounts
./sandbox goal account list
# [offline] HCNMMIL3MKYILOLUO74NF6OPCJU4RU7IE5PX6JYBIT5YHAMQIVO5YADHMU
HCNMMIL3MKYILOLUO74NF6OPCJU4RU7IE5PX6JYBIT5YHAMQIVO5YADHMU 1000000000000000
microAlgos
To connect to the sandbox using an SDK, you can use the below connection object.
Summary:
Windows
Note: Be sure to use the latest version of Windows 10. Older versions may not work properly.
Sandbox supports two primary modes of operation. By default, a private network will be created, which
is only available from the local environment. There are also configurations available for the public
networks which will attempt to connect to one of the long running Algorand networks and allow
interaction with it.
To specify which configuration to run:
./sandbox up $CONFIG
./sandbox up dev
./sandbox down
./sandbox clean
./sandbox up $NEW_CONFIG
Using third-party API services to access native Algorand REST APIs for the mainnet, testnet, and betanet
like service providers are Purestake and Rand Labs. Developer can access these services via an API key
and Algorand node address.
https://developer.purestake.io/
https://randlabs.io/
Linux / OSX
build
make install
test
# unit tests
make test
# integration tests
make integration
Running a node
Once the software is built you'll find binaries in ${GOPATH}/bin, and a data directory will be
initialized at ~/.algorand. Start your node with ${GOPATH}/bin/goal node start -d
~/.algorand, use ${GOPATH}/bin/carpenter -d ~/.algorand
You can run a node out of other directories than ~/.algorand and join networks other than
mainnet. Just make a new directory and copy into it the genesis.json file for the network. For
example:
mkdir ~/testnet_data
cp installer/genesis/testnet/genesis.json ~/testnet_data/genesis.json
${GOPATH}/bin/goal node start -d ~/testnet_data
Genesis files for mainnet, testnet, and betanet can be found in installer/genesis/.
Set PATH:
There are two methods for installation:
The package manager method uses fixed directories and automatically updates. It has been
validated on Debian, Ubuntu, Fedora, and CentOS.
The updater script method allows manually setting data directories and requires manual updates.
It has been tested on the same Linux distributions from above, as well as on Raspbian (Raspberry
Pi 3), openSUSE Leap, Manjaro, Mageia, Alpine, and Solus.
algod –v
sudo -u algorand -E goal account listpartkeys
curl -O https://releases.algorand.com/rpm/rpm_algorand.pub
sudo rpmkeys --import rpm_algorand.pub
sudo yum install yum-utils
sudo yum-config-manager --add-repo
https://releases.algorand.com/rpm/stable/algorand.repo
To install to Fedora or CentOS 8 Stream, open a terminal and run the following commands.
curl -O https://releases.algorand.com/rpm/rpm_algorand.pub
sudo rpmkeys --import rpm_algorand.pub
dnf install -y 'dnf-command(config-manager)'
dnf config-manager
--add-repo=https://releases.algorand.com/rpm/stable/algorand.repo
dnf install algorand
Start Node
Installs by a package manager automatically start the node. Starting and stopping a node should
be done using systemctl commands:
Installing on a Mac
mkdir ~/node
cd ~/node
curl https://raw.githubusercontent.com/algorand/go-algorand-doc/master/
downloads/installers/update.sh -O
Ensure that your system knows it's an executable file.
Installing on Linux
Nodes have been verified on Ubuntu, CentOS, Fedora, Raspbian (Raspberry Pi), openSUSE Leap,
Manjaro, Mageia, Alpine, and Solus. Other modern distros should work as well.
When the installer runs, it will pull down the latest update package from S3 and install it.
Start Node
Installs by the updater script require that the node be started manually. This can be done with the
following command:
pgrep algod
To launch the debugger locally, for use with the CDT, execute the following command from a
terminal.
1.) Python:
Algorand provides an SDK for Python which is available as a pip package. To install the Python SDK, open
a terminal and run the following command:
Before the transaction is considered valid, it must be signed by a private key. Use the following code to
sign the transaction.
Submit the Transaction
The signed transaction can now be submitted to the network. wait_for_confirmation is called after
the transaction is submitted to wait until the transaction is broadcast to the Algorand blockchain and is
confirmed.
To view the transaction, open AlgoExplorer or Goal Seeker and paste the transaction ID into the search
bar.
https://testnet.algoexplorer.io/
https://goalseeker.purestake.io/algorand/testnet
Set Up Your Editor/Framework
Steps
1. Download VS Code
2. Install Extensions
3. Debugging with VS Code
4. Debugging JavaScript with VS Code sample
Open VS Code. Visual Studio Code includes built-in JavaScript IntelliSense, debugging, formatting, code
navigation, refactorings, and many other advanced language features.
In this step, setting up a debug session for a JavaScript code is covered for both a standalone
code file as well as through a browser. The steps are similar for all languages.
Task: Standalone
B) Select from the drop-down menu to Add Config (for the current folder)…
Select Debug and Add Config
Select the desired debug method. Here the section is set to Node.js: Launch Program.
VS Code stores debug configurations in a file called launch.json inside of the .vscode folder in your code
folder. The editor should pop up with the launch.json file. Change the name and program to match your
code file to debug.
Now the debugging can start. Select your new launch configuration form the list.
To set a breakpoint, simply click on the left margin, sometimes referred to as the gutter, on the
line to break.
Set breakpoint.
Your breakpoint should be hit, and the program execution paused on the line of your breakpoint.
It is highlighted.
Debugging.
A) Breakpoint
D) Navigate by selecting run (to next breakpoint), step over, step into, step out of or stop
2. Algorand Studio
Develop Algorand smart contracts in either TEAL or PyTeal with language support and integrated
compiler.
Install and Run Algorand nodes.
Construct transactions with support for most Algorand features, including atomic transfers,
multi-sig signing, asset creation and transfer operations, and contract executions.
Manage keypairs and sign transactions.
Query account and transaction information using the integrated explorer.
Make transfers
VS Code Extension for Algorand
Prerequisite
VS Code
Docker for Desktop (this extension uses docker to run Algorand node and Algorand compiler)
Installation
Download the built extension in the releases. Open the Extensions page in VS Code and select Install from VSIX...
1. Open a *.teal or *.pyteal file
2. Press Cmd+Shift+B to call out the compiler task
3. For the first time running the compiler, you will probably see the No build task to fun found. Configure Build
Task... notification. Click it and you will see an option Algorand Compiler: TEAL or PyTeal. Click it again and VS Code
will configure a tasks.json file for you. Switch to your .teal or .pyteal file and click Cmd+Shift+B to
compile
Algorand Panel
Algorand Panel is a dedicated interface for Algorand-related operations, accessible through a button at the left of the
bottom bar. Please make sure you have installed and started Docker before using the Algorand Panel.
Install Algorand node (algorand/stable) - This is the official docker image for Algorand node. Click the New
Instance button and click the Algorand version to open the dropdown. You can install and manage Algorand nodes
in the Algorand Version Manager.
Manage Algorand node instances - Click the New Instance button, enter the instance name and select a version
for algorand node to create a new instance. The extension will download the network snapshot to expedite the
sync process.
Start a local node - Just click the Start button
Display node logs - Shown in VS Code terminal
3. Algorand blockchain using IntelliJ IDE.
AlgoDEA IntelliJ plugin provides end to end development life-cycle on the Algorand blockchain
using IntelliJ IDE.
Using this plugin, developers can create and test both stateless and stateful smart contracts directly
from their IntelliJ IDE. Some of the other key features supported by this plugin are editor support for
TEAL & PyTeal files, ASA management, Atomic Transfers, Test account management.
The goal of this plugin is to increase developer productivity by simplifying various interactions with the
Algorand blockchain. Due to simple consistent development workflow in the IDE, developers can iterate
faster during the development stage
Account Management
Using this feature, developers can create & manage both standard and multi-signature accounts. These
accounts are easily accessible from different Algorand specific functionalities in the IDE .
Node Configuration
Developers can add or configure one or more Algorand Nodes inside their IDE. The supported node
types are custom Algorand Node, Purestake.io node and Sandbox.
TEAL Support
The plugin supports various editor level features for TEAL files. Below are the few key features
supported in the editor for the TEAL file type.
Developers can also create PyTeal files and use them in stateless or stateful smart contracts. With the
“PyTeal Compile” option, a PyTeal file can be easily compiled. All editor level support is enabled by the
default Python plugin in IntelliJ IDE.
Developers can easily create, and test stateless smart contracts directly inside their IDE. The plugin
comes with many out-of-box stateless smart contract templates.
A dedicated user interface simplifies the creation of logic Signatures as well as sending a transaction
signed with a logic signature.
Stateful Smart Contract
The plugin supports the full lifecycle of stateful smart contracts. All types of stateful smart contract
transactions are supported through a dedicated user interface.
Payment Transaction
Using this feature, developers can easily transfer Algo or any ASA from one account address to another.
It simplifies the complexity of creating, submitting and monitoring a payment transaction through a
simplified user interface.
Atomic Transfer
The creation of an Atomic Transfer transaction is a multi-step process. With an intuitive user interface,
the plugin simplifies this process. Users can quickly create and submit Atomic Transfer transactions.
Asset Management
The plugin supports full lifecycle of the Algorand Standard Asset inside the IntelliJ IDE. A new ASA can be
easily created, managed through the “Asset Management” UI. The standard “Transfer” UI supports both
Algo and Algorand Standard Assets.
Export Transaction
Using “Export Transaction” and “Export Signed Transaction”, developers can serialize a transaction to a
JSON file which can be used for different purposes later. These options are available through every
transaction submission UI in IntelliJ IDE.
Finally, make sure your yarn global bin directory is in your $PATH.
Installation from NPM
cd ~
yarn bin