Project Nine: an Algorand to ASA currency exchange

"You can create your own money exchange to trade coins with others? Wow!"

I attended a very good introduction to the concepts of Private Tokens and Smart Contracts: the USI Winter School course on Writing Smart Contracts (WSC) 2022 facilitated by Prof. Peter Gruber.

"Project Nine" is the end of course project. The specifications were:

  1. Use the Algorand Testnet blockchain to transact Algos for Marketcoin ASA (see the article) via a smart contract. The smart contract will pay 10 Marketcoin for 1 Algorand.
  2. Allow the buyer of Marketcoin to use those as payment to "enter" a private area of the website and "purchase" content.
  3. Connect to the website from a wallet to validate identity.

The implementation

Since the course used Jupyter Python notebooks, PyTeal (for writing smart contracts) and the Python Algorand library, I thought a Python/Flask webapp would be ideal for this.

The implementation is slightly different from the specs:

  1. You can transact Algos to ASA via a "currency exchange" - I decided on this since Testnet Algorand dispensers usually drip 5 or 10 Algorand at a time, and large transactions would require multiple visits to either the dispenser or the smart contract (due to hardcoded amounts, link to come soon). As we now have a (very modest) currency exchange, the client can buy or sell any number of Marketcoin - for this exercise I decided to peg the exchange at 1 to 1. Transactions within the Algorand network carry the usual 0.001 Algo fees.
  2. I elected to implement a simple graphic using Apexcharts.js and ASA-related data from the REST interfaces of To fetch the dataset I used SuperAgent to initiate and return a JSON object via an AJAX call.
  3. Linking an exchange to a mobile wallet is much more complicated than it sounds - the technology is in early stages and the amount of work to make this work seamlessly is beyond my time allocation. More information on the WalletConnect tech is available here.

Does it work?

Yes it does work.

"Project Nine" is archived in GitHub - it was released under a "Creative Commons" license - you are free to download and use as you see fit.

You'd be wise to test what you find in the Internet before you use it. All code examples are provided "as-is".
"Elegant code does not exist: it either solves a problem or it does not."