Smart Contracts Status Report
Gupta, who is VP of Technology at Hiro, kicked off his talk by defining some terms. “In some circles, saying things like DeFi on Bitcoin or smart contracts for Bitcoin can be confusing at best... and triggering at worst,” he said. “So let me start by defining what I mean by smart contracts for Bitcoin…”.
For Gupta, smart contracts for Bitcoin must be:
- Permission-less
- Trust-less
- React to BTC state
- Change BTC state
Next, Diwaker took a look at how Clarity, the smart contracting language which runs on Stacks blockchain, holds up to these standards. “Based on what we've seen in the ecosystem so far, Clarity on Stacks meets the bar for being a permission-less and a trust-less environment. So now, the key questions are, can a Clarity contract react to events happening on the Bitcoin chain... and can they make state changes on Bitcoin? Because then, you have a really full-fledged system!”
“Can [Clarity contracts] make state changes on Bitcoin? Because then, you have a really full-fledged system!"
He then shared a recent, real-world example that supports Clarity’s ability to react to events happening on the Bitcoin chain. Someone in the Stacks community recently executed a trust-less swap of an NFT on Bitcoin, using a Clarity contract on Stacks. First, the NFT was transferred to a smart contract on Stacks. Then, a regular transaction was made via Bitcoin. That triggered the smart contract to verify that the Bitcoin payment did actually occur, and when this verification was completed, the smart contract released the NFT to the payee. “Note that the only thing someone had to do to actually trigger the swap is to send a regular Bitcoin transaction to a specific wallet. That's it,” said Gupta.
As to the question of whether or not Clarity contracts can make state changes on Bitcoin, Gupta says Stacks is making progress. Stacks miners are currently generating Bitcoin transactions whose outputs are governed by the Stacks consensus protocol. “Large parts of the consensus mechanism in Stacks are expressed in a smart contract, and what the smart contract does then influences the Bitcoin transaction that Stacks miners send out,” said Gupta. “This is an active area of research in the Stacks community right now.
So now that Clarity on Stacks can enable smart contracts for Bitcoin, what can you do with it? For one, Gupta says, devs can create truly differentiated DeFi products on Stacks. “Imagine a negative interest loan that pays itself back over time, or an NFT that is earning a passive yield in Bitcoin, or programmable Bitcoin futures,” said Gupta. “These are all uniquely possible only on Stacks because of the consensus mechanism and the access to Bitcoin state that Clarity contracts can have.”
Writing a Clarity Smart Contract on Stacks
Would you ever sign that contract that you couldn’t read? Can you imagine putting your name on the dotted line for a mortgage in a language you don’t know? Then why would you do the same with a smart contract? These are the questions Marvin Janssen, Technical Lead at the Stacks Foundation, posed at the start of his developer’s session about building smart contracts with Clarity.
“Why would you interact and submit your tokens to a smart contract that you can't read, that's compiled into byte code that's very difficult to analyze for its correctness, and that may have hidden features that you don't know about? That’s why Clarity is interpreted,” Janssen explained. “That way, how you write the contract is exactly how it's going to be broadcast on-chain and deployed.”
In addition to being interpreted as opposed to compiled, Janssen delved into some of Clarity’s other benefits, including:
- Clarity is decidable (non-Turing complete)
- Reentrancy is not permitted
- No underflows and overflows
- Built-in support for custom tokens/your own NFTs
- Transactions are secured by post-conditions
After giving context to some of the language’s strengths, he drilled down on how to build a Clarity basic smart contract on Stacks with a helpful tutorial (to get his step-by-step instructions, view the full video). Then, he answered audience questions about reentrancy, writing for multiple NFTs, and getting started with Clarity.
Janssen also shared some exciting news about a new initiative: Clarity Universe. “The Stacks Foundation is spearheading this educational project which anyone can join, whether you’re a beginning developer, you're just interested in developing but haven't done anything quite yet, or are experienced,” he said. “You can learn Clarity from start-to-finish, and it’s free to join. You'll work on projects, and we'll provide a pathway for you to get funding if you have an amazing idea. We also have a grants program with the Stacks Foundation. So, if you have an idea that moves forward that user-owned internet, come talk to us. We can give you the resources you need to build.”
To learn more, listen to Diwaker Gupta and Marvin Janssen’s full talks, or sign up to join the Clarity Universe.
Thanks to Shannon Voight, Events Lead at Stacks Foundation, for contributing to this post.