Taking your First Steps with Cadence

Joshua Hannan
6 min readFeb 11, 2021
The F also stands for FUN!

Hello! My name is Josh Hannan and I am a smart contract engineer on the Flow Team at Dapper Labs. I’ve been in the blockchain space since early 2017, spent a few years working on Ethereum projects, and started working with the Flow team in September of 2019. At Dapper Labs, I write Cadence smart contracts and documentation, and help with community efforts.

I’m going to write short (sometimes not-so-short), weekly (assuming I hit all my deadlines) blog posts about what is currently at the top of my mind relating to Cadence smart contracts. I’ll also highlight interesting projects in the community that I come across, and I may even have guest writers contribute every once in a while!

I thought about calling this series, “Josh’s Weekly Cadence,” but that pun has been completely driven into the ground in the Flow community and should never be heard again, so I won’t subject you to it on a weekly basis.

Cadence is a fascinating language, and I want to do everything I can to start more conversations about it.

What is Flow?

Flow is a new blockchain built for the next generation of apps, games, and the digital assets that power them. Flow’s unique architecture allows it to scale without sharding, while still providing the same decentralization and security that everyone expects from a blockchain.

Its ok, you can take your time here. I watched this gift on repeat for about 10 minutes the first time I saw it.

Where to Start?

Recently, there has been a lot of new interest in Flow. Maybe everyone made New Years’ resolutions to learn about Flow? Maybe Flow was mentioned in an Elon Musk Tweet™? Maybe there is an NFT game built on Flow that is skyrocketing in popularity, and driving developers who want to build tools for it and other similar experiences? Impossible to say for sure. 😜

Either way, there are a lot of new people in the Flow community, and a lot of people who want to learn about Cadence. It isn’t always clear where to start though, and where to go after you’ve learned the basics.

First, if you are completely new to blockchain, I highly recommend that you find a guide or online course that introduces you to the basics of distributed ledger technology (out of the scope of this post) before continuing on your Cadence journey.

I also recommend reading the Flow Primer to build a basic understanding of the architecture of the Flow blockchain.

Step 1: Cadence Introduction

The Introduction to Cadence does a great job explaining the important design decisions behind Cadence and why they are important. It is vital to understand before trying to learn the language.

I also recommend checking out this blog post from Dete Shirley, the CTO at Dapper Labs and one of the lead architects of Flow and Cadence, who is only a few memes and viral tweets away from achieving cult status. He explains why the Cadence programming model, resource-oriented programming, is the ideal model for digital assets.

One more blog post to read about the Flow and Cadence account model is this one from Decentology:

They do a great job outlining what makes the Flow programming and account model unique and special.

About time for a break, right? No? Well don’t let me hold you back!

Step 2: Cadence Tutorials

Next, you should complete all of the Cadence Tutorials, starting with First Steps and ending with Voting Contract. These tutorials use real contracts to walk you through the important features of Cadence step-by-step.

The tutorials will help familiarize you with the Flow Playground, an amazing tool to quickly write and manually test your smart contracts in your browser!

Just a taste

There is also a Visual Studio Code extension you can install to have syntax highlighting and a built-in Flow emulator in VSCode! Pretty neat, right?

Step 3: Standard Interfaces

As you’ll learn in the tutorials, many blockchain projects use fungible tokens, non-fungible tokens, or both, even if they don’t actually need to.

There are standard interfaces for both types that we highly recommend you utilize in order to be interoperable with other smart contracts. They are each in a separate Github repository.

Fungible Token Standard

Non-Fungible Token Standard

These will be your first examples of smart contracts that are actually deployed on Flow Mainnet and used in real applications.

Step 4: Advanced Cadence Topics

Once you have a good grasp on the basics, dive into some more detailed explanations of Cadence features. The formal language reference is a great resource that every Cadence developer should read through if they have the time, and the docs site has recommended Cadence design patterns and anti-patterns that every developer should be aware of in order to maintain clear and safe code.

Also Step 4: Real Cadence Contracts

By this point, I’m sure you have been fully indoctrinated into the Cadence cult and are itching so see what others have built with this incredible programming language.

No? Did you drink some of the delicious kool-aid over there? It is quite tasty. Yes, there you go. Now you understand.

Now that we’re on the same page, here are some great examples of Cadence smart contracts that are running on testnet and/or mainnet. (I might be a bit biased because I helped write a few of them.)

Flow Core Contracts: This repo contains the smart contracts and transactions that are part of the core Flow protocol. They enforce behavior for the Flow network token, fees, staking, epochs, and more.

Kitty Items: The Flow and Cryptokitties team recently put together this amazing example of a NFT game, marketplace, and application that uses the latest cutting-edge best practices for Cadence and Flow development in full application that is running on testnet!

NBA Top Shot: You might have heard of this one. Top Shot and its marketplace have been running on Flow Mainnet since June 2020 and has become extremely popular. DISCLAIMER: The Top Shot contracts were written a long time ago and therefore use some Cadence design patters that are outdated and not recommended for most NFT projects going forward. The Kitty Items project is a much better example for Cadence best practices.

Conclusion

If you made it this far, congrats! You should hopefully now have enough tools and knowledge to write your own smart contracts in Cadence.

Along the way, you have the entire Flow team and community to support you! Please do not hesitate to reach out via our Discord server, the Flow Forum, or via an issue in the Flow Github repo.

Are there any other resources or interesting projects that you know would useful to newcomers? Feel free to comment with your ideas and I might include them in a future post!

Flow Discord: https://discord.gg/flow

Flow Forum: https://forum.onflow.org

Flow Github: https://github.com/onflow/flow

See you next week! 👋

--

--

Joshua Hannan

Smart Contract Engineer at Dapper Labs, working with Cadence, the best language for smart contracts!