First Attempt on Algorand

KC Tam
8 min readMay 19, 2020

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

  1. Setup a private network for our demonstration
  2. Create wallet and accounts
  3. Perform Algos transfer between accounts
  4. Issue and transfer of digital assets
  5. Perform atomic transfer to simulate “buying asset with Algos”

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.

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

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

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,

Default wallet and account in Primary

On Node,

Default wallet and accounts in Node

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

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.

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

Here are the wallets and accounts created for demonstration.

Wallets and accounts for demonstration

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

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.

Send some Algos to our newly created accounts for demonstration.
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.

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.

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.

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

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.

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.

Bob’s account opt-in.

Now Alice can send aCoins to Bob.

Asset transfer is successful

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

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

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

  1. Create two one-side transactions, one from Alice and one from Charlie, on their part of transaction.
  2. Combined them together into a file (combined.tx).
  3. Group the file (grouped.tx). This is to create a group ID to bind them together.
  4. Since Alice and Charlie is in two different nodes, split the group file into two parts.
  5. Let Alice and Charlie sign their own portions.
  6. The result file is combined again (signout.tx).
  7. Send raw transaction with this resulting file.

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).

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.

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

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).

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

Before sending, checking Alice and Charlie’s accounts

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.

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.

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

Now let Charlie’s account opt-in.

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.

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.

Transaction completes: Alice gets Algos and Charlie gets aCoins.

This is what happens in our demonstration about atomic transfer.

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.

--

--