First Attempt on Algorand

Overview

This article is my study note about Algorand. While Algorand comes with the advanced technologies in particular the consensus algorithm, I am more interested in what I can do on this platform as a user or a developer. As a result I start trying several major functions available on the platform and jot down here what I have learnt. Hope this article serves as an illustrative overview about Algorand, what it can provide and how things work from a user perspective.

The features I am interested in particular are digital asset (Algorand Standard Asset, ASA) and atomic transfer. Algorand implements the digital asset natively inside the platform (known as layer-one approach). This is different from the popular Ethereum platform, which implements digital asset through contract code and execution environment. Meanwhile, atomic transfer enforces group of transactions to be executed all together or none of them, enabling certain use cases of exchanging assets in real life.

In this article I am using the command line, goal, to perform the demonstration. Algorand comes with software development kits (SDKs) for major coding environments. Last but not the least, the documentation is really well structured, and good for people like me who did not know Algorand a month ago can easily pick up the ideas and do hands-on practice.

The flow of this article is like this

Here you can find the documentation of Algorand.

Setup a Private Network

My demonstration is done on a private network with two nodes running on a host. This setup is based on this tutorial.

In the private network net1, two nodes Primary and Node are deployed (we keep capital for the node name). As this demonstration is deployed on a single host, these two nodes are running as two processes, and their material is stored in directories net1/Primary/ and net1/Node/, respectively.

In the network setup file we have created some accounts, preallocated with Algos (native currency in Algorand, 1 Algo = 1,000,000 µAlgo) and the consensus has been established. The network is assumed working fine and our demonstration is done on top of this private network.

Image for post
Image for post
The Private Network net1 with two nodes: named Primary and Node

Here is how the network status after bringing up the network.

Image for post
Image for post

Wallets and Accounts

Examine Existing Wallets and Accounts

We first observe the wallets and accounts created according to the network setup. They are preallocated with Algos and already participating in the consensus algorithm. This helps making the network working well.

On Primary,

Image for post
Image for post
Default wallet and account in Primary

On Node,

Image for post
Image for post
Default wallet and accounts in Node

Here is what we have after bringing up the network net1.

Image for post
Image for post
Default wallets and accounts created for net1.

Create Wallets and Accounts for Demonstration

We will not use the default wallets and accounts shown above, but create our own wallets and accounts for demonstration. The account setup is like this. Both Alice’s and Bob’s wallet and account are created in Primary. Charlie’s wallet and account is in Node.

For demonstration purpose, no password is set and backup phrase is not shown. In real life make sure one uses password to protect the wallet and a backup phrase for wallet recovery.

Image for post
Image for post
Alice’s wallet and account created in Primary
Image for post
Image for post
Bob’s wallet and account created in Primary
Image for post
Image for post
Charlie’s wallet and account created in Node

Here are the wallets and accounts created for demonstration.

Image for post
Image for post
Wallets and accounts for demonstration

And we see no Algos available in these three newly created accounts yet.

Image for post
Image for post

As the default accounts of each node have Algos, we will send 100 Algos to each of them. Detail of sending Algos command is shown in next step.

Image for post
Image for post
Send some Algos to our newly created accounts for demonstration.
Image for post
Image for post
Now all accounts have 100 Algos (100,000,000 µAlgos)

Transfer Algos between Accounts

Now we are showing how to send Algos between accounts. Let say Alice sends 10 Algos to Charlie.

We first check Alice’s and Charlie’s accounts. After Algos are sent, we will check them again.

Image for post
Image for post

We see that 10 Algos are now transferred from Alice to Charlie. Meanwhile, 1000 µAlgos is paid as fee from Alice (payer).

Algorand Standard Asset (ASA)

ASA is how Algorand implements digital asset. The implementation is native inside Algorand platform. For those familiarized with Ethereum, the digital asset is always implemented as contracts implemented in an execution environment (EVM). In Algorand, we do not need to deploy contracts. Instead, we can issue digital assets directly.

In this demonstration Alice is issuing AliceCoins (aCoin). The total amount of aCoin to be issued is 10,000. And Alice sends 100 aCoin to Bob.

Issuance of ASA

This is how Alice issues aCoin on the network.

Image for post
Image for post
Alice issues aCoin directly on the network.

Check information of this token. All 10,000 aCoins are now in reserve, and none is issued. The reserve is Alice’s account if not changed.

Image for post
Image for post

Check Alice account. Now Alice account has some amount of Algos and 10,000 aCoins just issued.

Image for post
Image for post

Transfer of ASA

Any account must opt-in before receiving the asset. Here Alice is sending 10 aCoins to Bob. Since Bob’s account has not opt-in yet, the asset transfer fails.

Image for post
Image for post
Bob’s account cannot receive asset because it does not opt-in yet.

Account opt-in is a process that one sends zero amount of that asset to oneself.

Image for post
Image for post
Bob’s account opt-in.

Now Alice can send aCoins to Bob.

Image for post
Image for post
Asset transfer is successful

Now check balance of Alice and Bob. They have the right amount of aCoins after the transfer.

Image for post
Image for post

And asset information about aCoin. We see 10 aCoins being issued. Those remaining is still in reserve, and total amount is not changed.

Image for post
Image for post

Atomic Transfer

Algorand supports atomic transfer, which means a number of transactions can be processed all together or none of them. This is always needed in exchanging assets, to reduce situation that one side hands over the asset while cannot receive those from other side.

In our demonstration, Charlie is buying Alice’s aCoin. Assuming an exchange is to be made such that Charlie gives 10 Algos to Alice, and Alice gives 100 aCoin to Charlie. This needs to be an atomic transfer to ensure no partial transaction happens.

The flow is summarized in this flow

First we need two one-side transactions, one from Alice and one from Charlie. These transactions are not sent to network yet. They are output as a transaction file (a_to_c.tx and c_to_a.tx, respectively).

Image for post
Image for post

Combining a Transaction into a file (cat a_to_c.tx c_to_a.tx > combined.tx), and group the result into a group transaction file.

Image for post
Image for post

Now the grouped transaction file contains a group identity. As both accounts are in different nodes, we split this grouped transaction file for signing.

Image for post
Image for post

Signing the portion by Alice and Charlie, respectively. Again, the signed result is not yet sent to the network, but kept as a file (-o).

Image for post
Image for post

Finally, combined the signed portion into one. This is the file to be sent to the network.

Image for post
Image for post

Before sending, checking Alice and Charlie’s accounts

Image for post
Image for post
Alice has around 90 Algos and 9,990 aCoins, and Charlie has 110 Algos with no aCoin.

When we send this signout.tx, we saw an error. The error is due to that fact that Charlie has not yet opt-in to receive the aCoin.

Image for post
Image for post

We have simulating a failure here! Check the balance again on both Algos and aCoins. We see the no partial execution of this grouped transaction. All balances remain in both accounts. This is how atomic transfer protects against partial execution.

Image for post
Image for post
No change on balance of both Alice’s and Charlie’s account

Now let Charlie’s account opt-in.

Image for post
Image for post
Opt-in process: send zero amount of asset to oneself.

Before sending the transaction again, remove the rejected transaction file, created in the last failure.

Image for post
Image for post

The transaction is done. And we see the balance of both accounts updated. Alice gets 10 Algos from Charlie, while Charlie gets 100 aCoins from Alice.

Image for post
Image for post
Transaction completes: Alice gets Algos and Charlie gets aCoins.

This is what happens in our demonstration about atomic transfer.

Image for post
Image for post
Atomic transfer: either all are processed, or none of them.

Summary

In this article we performed some transactions on an Algorand private network using command line. We saw how to bring up a private network and create wallets and accounts. With these we demonstrated how Algos are transferred between accounts, and how digital asset (ASA) is issued and transferred. Finally, we used atomic transfer to simulate a case of asset exchange. I hope this is good enough for those who are new to this platform, and wish to further explore more other functions.

Written by

Happy to share what I learn on blockchain. Visit http://www.ledgertech.biz/kcarticles.html for my works. or reach me on https://www.linkedin.com/in/ktam1/.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store