Introduction to Cardano’s Smart Contract Platform

Robin Böning
5 min readApr 29, 2021

In this article I am explaining some basics of Cardano’s smart contract platform and what you should prepare before throwing yourself into the cold water.

Speaking of water, have you ever tried scuba diving? I’ve only tried it once so far. It was a fun experience but it was also a bit scary. Lets talk a bit about scuba diving…

Hold on, what? Scuba diving? I thought we are going to talk about smart contracts in Cardano!?

Yes, don’t worry. You’re in the right place. We’ll get there, but before you jump off your pretty and comfortable yacht to dive deep into the dark blue ocean, you want to make sure you’re prepared, right? Riiight?

So, what do you need to prepare for a first real dive?

  • Adequate swimming skills
  • Basic principles of scuba diving
  • The right equipment
  • Confined water dives

After checking off the last item on the list, I headed out for my very first scuba diving trip. As I said, it was a little scary as I was completely taken out of my comfort zone. Nevertheless, I had a lot of fun and took away many new experiences from this first trip.

Okay, let’s make a switch now and talk about Cardano. Anyhow, I’ll come back to our little scuba diving story here and there as it compares nicely to my first experiences with Cardano’s smart contract platform.

Disclaimer

I am currently attending the Plutus Pioneers program. It means I am one of the first few persons studying and playing around with Cardano’s new Smart Contract Platform called Plutus. As of today, it is not yet rolled out on any network but only available as a simulated environment and the API is still changing frequently. Hence, this article might already be partially outdated when you’re reading it.

The first two bullets

A Plutus contract is written in a single Haskell program. It consists of two parts: The code that runs on the blockchain and the code that runs off chain (for example in the user’s wallet).

During compilation, the two parts are treated differently. The off-chain part gets compiled like any normal Haskell program. The on-chain code is compiled into Plutus Core (also referred to as Plutus Tx since this part of the code is submitted to the blockchain within a transaction). This is done by a compiler plugin intercepting the on-chain part of the code and pushing it into a different compilation pipeline.

Nevertheless, thanks to some meta programming magic with Template Haskell, you can share types and definitions between the two parts.

The Plutus stack consists of many different Haskell packages with many types and definitions and as already mentioned even a compiler plugin. We don’t need to worry though, as most of it is only used internally and we only use a small subset directly.

Plutus Core is the previously mentioned language on-chain scripts are written in. Contract developers DO NOT write Plutus Core directly, it is the language produced by the compiler only.

Plutus Ledger, Plutus Contract, Plutus Errors are some packages providing a lot of functions we can utilize when writing contracts.

If you want to learn more about the Plutus stack I recommend checking out the architecture doc on GitHub and this IOG article explaining the compilation pipeline in more detail. If you’re interested in seeing the latest list of packages check the stack.yml in the master branch of the Plutus repository.

Alright, this is already a lot to read up on and digest…

Let’s stop for a second and pull out the scuba diving checklist. Look at the first bullet point, and you may have guessed it, replace swimming with Haskell.

You need adequate Haskell skills

Learning Haskell

If you just search for Haskell on the internet, you might find the official introduction page.

Haskell is a computer programming language. In particular, it is a polymorphically statically typed, lazy, purely functional language, quite different from most other programming languages

https://wiki.haskell.org/Introduction

I know, that doesn’t sound easy. I don’t want to make it sound easy either, because it isn’t.

Try to remember your first swimming course. Was it easy? I don’t remember thinking about whether it was hard or not, but I do remember that I wanted to learn to swim and that I developed fun in learning. This intrinsic motivation is the key to successful learning.

Learning Haskell is a project on its own. Obviously, I can not cover that in this article. I can only share some great sources for learning the Haskell basics. I am still going through those as well.

Graham Hutton, Professor at the University of Nottingham has recorded his lectures for an introductory and an advanced Haskell course. You can find them here:

Don’t forget to thank him, he is on twitter @haskellhutt.

There is also a free book called Learn You a Haskell For Great Good! — It is available to read online but you can also buy the printed version for a fair price: http://learnyouahaskell.com/

Cardano’s accounting model

I am happy you’re still reading, that’s great!

Knowing some Haskell is a very important prerequisite for writing smart contracts on Cardano, but those programs are distributed to nodes deployed everywhere in the world and they are executed within the context of a blockchain, specifically Cardano’s blockchain. Obviously, we need to understand how this effects our program and what this allows us to do. We need to understand how the Cardano blockchain works, or at least some core parts of it.

Lets take a look at the second point of our scuba diving checklist and cross out scuba diving and replace it with Cardano’s accounting model.

Basic principles of Cardano’s accounting model

Unfortunately I can not cover this topic in depth as it would take an entire article by itself. Since this topic is pretty well documented I will just provide some links and encourage you to read them.

If you are familiar with Bitcoin’s UTxO model, it will be rather easy for you as Cardano basically builds on top of that and implements the so called Extended Unspent Transaction Output model (EUTxO model).

I hate stating the obvious, but I want to drop a couple of additional notes that I believe are worth mentioning:

The blockchain consists of immutable information only. Simply put, it can NEVER change. You can only add another piece of information on top of it treating it as the new version of the former.

You should also know the blockchain can NEVER trigger an event by itself. It ALWAYS requires a trigger from the outside, in the form of a transaction.

Let’s wrap it up here. I think this was enough information for the moment.

If you are hooked, I suggest you start studying until you can tick off those first two bullet points. My next article shall cover the other two bullets.

You can reach out to me on twitter @lacepool_com. I am happy to receive your feedback!

Advertisement: I am operating a Cardano Stake Pool called [LACE] Open Source Software Fund. I am more than happy if you support my endeavour by delegating to my pool.

--

--