September 21, 2021
Inside Clarity Universe Vol 2:
Stacks and The City, Field Trip Edition
by Caitlin Eckvahl on September 21, 2021
Hello! Welcome to Inside Clarity Universe Volume 2, the blog series where we get a peek into the intensive 6-week coding program that is Clarity Camp. Our first cohort is currently in the midst of learning everything they need to be successful with smart contracts for Bitcoin. This week, Clarity Camp was jam packed with lessons and students dug into dapps, learned about time-locked contracts and Proof of Transfer, and even ventured on a virtual field trip to Miami, the newest Crypto Capital. If you are craving that same nostalgia from The Magic School Bus, you are going to want to stick around til the end!
A Lesson on Dapps
In order to get started with building the next generation of dapps or decentralized applications, students are going to need to learn from the dapps of today and the dapps of the past. Instructor Tina, examined the top 10 dapps on (ranked by 30 day volume at the time of writing) and extrapolated their unique architectures and what makes these popular dapps so appealing to others. Here are some of the current trends in the dapp market:

  • Most apps are built on Ethereum. As it stands, Ethereum has been king of dapps to date. All top 10 dapps were built on Ethereum and this is likely because Ethereum has historically made it very easy for decentralized applications to be created and deployed on its network (before Clarity that is).
  • DeFi is still hot! Students were quick to notice that out of the top 10 dapps listed, that nearly all of them were siloed in DeFi or decentralized finance, making it very obvious that financial applications focused on borrowing and lending make up the majority.
  • NFTs are on the rise. Only one of the top 10 dapps was NFT related. NFTs are clearly a trendy and growing area in the dapp space, and dapp creators are currently looking for improved ways to buy, sell, secure, and display NFTs.
  • Smart contracts are important. Smart contracts and dapps actually go hand in hand. Dapps have a frontend component that interacts with smart contracts on chain. Dapps are similar to how conventional websites act as a face while on the backend smart contracts complete what is happening on chain.

With this newfound knowledge, students now have a good idea of the growing trends in dapp space and are ready to apply similar design rationales and formulas to build their own apps on the Stacks blockchain. The crypto community as a whole is always chasing what is next and if Clarity Campers play their cards right, the odds might land in the favor of Bitcoin-powered apps.
An Intro to Time-Controlled Contracts and Control Flow
Text editor showing the Clarity time-locked contract that Marvin walked students through. Credit: Marvin Janssen
For our Clarity lesson this week, Instructor Marvin walked students through setting up a time-locked contract that will lock up tokens over time. The idea behind this is that after a certain amount of time, the wallet within the smart contract will release these tokens to a beneficiary that is specified by the contract creator. This is similar to a will, college fund, or other important milestone where you would want to release funds to someone after a period of time and of course once certain conditions are met.

In order to create these kinds of contracts, Marvin introduced the concept of control flow to students. Similar to an order of operations in math (try to recall PEMDAS), control flow in Clarity is the order in which expressions are evaluated. When a smart contract is executed it goes through the expressions in a certain way, and some expressions can influence that control flow. Marvin explained how an assertion is a kind of check that exits the call if something is amiss. This check is to make sure enough time has passed before the beneficiary can collect the tokens.

After getting the basics down, students opened up their text editors and had the opportunity to code their own time-locked contract alongside Marvin. As you can see from the image above, Clarity is in fact very readable. By defining parameters like“new-beneficiary”, “unlock-at”, and “amount” it is easy for anyone to know what the intentions behind the smart contract are and what conditions are necessary in order for it to execute. Even for myself, as someone who doesn’t even know Javascript, I could easily look at this code and be able to understand that at the very least, this smart contract will do as it says.
If you are new to Stacks, you may have heard of Proof of Transfer (Pox), a technological phenomenon that connects Stacks to Bitcoin. For many, this is a technically complex topic but one of the great things about Proof of Transfer is that it is actually made up of a number of Clarity contracts on chain. Students will inevitably be using PoX in their applications so it was important to show them what it is, how it works, what role it plays in applications, and what its relationship with Clarity and Bitcoin looks like. So, to break down Proof of Transfer, we brought in Xan Ditkoff from Daemon Technologies who explains PoX better than I ever could:
“At the lowest layer we (Stacks) sit on top of Bitcoin. We only use Bitcoin for settlement, security, and the reserve asset. Bitcoin is as you could say, the truth for our overall system. We don’t try to do anything to Bitcoin or adulterate that job in any way; rather the Stacks blockchain sits on top of Bitcoin. It’s also a Layer 1 chain. It is not a Layer 2. It’s not a side chain. It is in and of itself its own Layer 1 chain.”

“The reason it has the ability to use Bitcoin for settlement and security is because of the novel consensus mechanism we came up with called Proof of Transfer. This is the consensus mechanism that allows the Layer 1 Stacks chain to connect to Bitcoin and settle down to it. Once we connect the two, we can have things like fully expressive smart contracts. You can do a lot of flexible things on top of that infrastructure because of Proof of Transfer.”
Proof of Transfer is made up of a number of Clarity contracts on the Stacks chain. Credit: Daemon Technologies
When we put that all together, we actually have a concept that is quite similar to Proof of Work mining, where you spend a valuable resource for the chance to compete to mint a new digital asset.

A lot of people often wonder why someone would want to tie a blockchain to Bitcoin given its current reputation for using copious amounts of electricity. Well, Proof of Transfer essentially makes it possible to reuse that initial energy spent mining bitcoin. The way to mine Stacks, instead of using electricity, is you spend bitcoin itself to mine STX, meaning you only have to go through that conversion of electricity to digital asset once. Think of it like melting down gold that was already mined in order to make a necklace; you don’t have to go out to the mine for more gold when you can reuse the original asset.

Miners have the ability to mine STX by spending bitcoin, but on the other side of the coin, Stackers somewhat do the reverse where they lock their STX and receive a reward in bitcoin directly from miners. When you really think about it, this is like magic: censorship resistant, permissionless BTC delivered right to your wallet.
Virtual Field Trip to Miami
To conclude our session, no class is complete without a field trip. We took our Clarity Campers on a virtual field trip to Miami to see MiamiCoin ($MIA), the first CityCoin, in action. If you haven’t already heard, the city commission of Miami recently voted to accept the funds generated by the Stacks ecosystem, making Miami not only a Bitcoin-friendly city, but a Stacks-fueled one at that. The funds will go toward initiatives targeting underprivileged communities, climate change and rising sea levels, and crypto education. Those who mine MiamiCoins are rewarded with STX which can then be Stacked for bitcoin.

Jason Schrader, a DevOps engineer at Freehold, took the class through an introduction to CityCoins and the Stacks technology that makes it all possible. CityCoins is just one of Stacks’ interesting use cases and is built using Clarity and Proof of Transfer. Jason explained that CityCoins was first created using a smart contract called PoX-Lite or “poxl” (coined and created by our very own Jude Nelson). One of the overall goals behind poxl was implementing Proof of Transfer in a smart contract. Clarity made it possible to create and design the smart contract while Proof of Transfer made it possible to Stack and mine CityCoins.

Jason discussed how Clarity played a part in setting certain parameters within the CityCoins smart contract including dictating how tokens were configured, how mining would take place, and how Stacking would be implemented. As we recall in Inside Clarity Volume 1, smart contracts only execute when certain conditions are met and one example of these conditions applies to defining token properties such as “no decimals, only a single unit”. This condition was a design choice set to avoid micro $MIA, essentially denominations that are too small to care about, similar to“dust” or micro BTC. Overall, students were blown away by the complexities behind CityCoins and learned how they could apply both Clarity and Proof of Transfer to their applications.

Most field trips end with a trip to the gift shop but our virtual tour ended with an exclusive invite to Miami’s hottest club, Club Hackathon. Jk. It’s not actually called that but if you are looking for a hot club I recommend Stacking.Club.

At MiamiCoin’s ongoing hackathon, Clarity Campers will have the chance to apply their newfound Clarity skills to build a working application that contributes to the core foundations of the MiamiCoin ecosystem/user experience. Winners will have both fame and fortune in the form of $25K bitcoin prizes and a spotlight in CityCoin’s blog page.

Caitlin is the Communications Lead at the Stacks Foundation where she provides PR and communications support to Stacks builders. Previously, she worked as a communications consultant at Wachsman where she worked with prominent crypto and blockchain companies including Stacks,, Rarible, Qredo, Value Technology Foundation, Status.IM, Binance Charity, and others.