Home
Info
Lexicon
Statistics

 

Info:

This is just an area where you can learn about blockchains and Cardano. Yes, there are lots of places on the internet you can do that, but I find a lot of it complicated and hard to navigate. Here, I keep it simple. I am trying to bust the jargon.


In this area I am giving an outline of the more technical aspects of using Cardano, as a user rather than as a developer that is. I mean making use of Plutus, Marlowe, etc to create smart contracts rather than wading in and submitting changes to the Cardano software itself. I won't teach you how to do it, just give you the background and point you where you need to go next.


Functional versus Procedural

A great start, to give you the right mindset, is to understand the nature of functional languages and see how they differ from procedural ones. You need this because Cardano smart contracts are built on Plutus, and Plutus is built on Haskell, using a similar structure, and this is despite the fact the Haskell is a little known and little used development environment. It has been chosen because it is a purely functional language, and this allows logical mathematical proofs to be built which show that it does what it is intended to do.

The process is:

  • 1. Write a specification.
  • 2. Make sure the specification is what you think it is.
  • 3. Convert the specification into a logical formal definition.
  • 4. Convert the formal definition into code.
  • 5. Verify that the code matches the formal definition.

Functional languages make this much easier, since they are designed to allow formal definitions of intent to be converted into code.


An example is a good way to see the difference

Procedural languages work the way most people think. So imagine you have a list of numbers and you want to add them up. You start with zero, add the first number to that, then add the second number to the that, then add the third, until you get to the end of the list. Easy. A programmer would have a count variable, and a total variable. They add 1 to the count variable meaning position number 1, then 2, etc, and each time they increment the position they add the value of the number at that position in the list. At the end the variable called "total" has the total value stored in it. Still easy.

In a functional language you have to think like a mathematician. The sum of an empty list is 0. The sum of a non-empty list is the value of the first element, plus the sum of the rest of the list. Thats it! For the sum of the rest of the list... see above. Its very clever, you define how to do things and they kinda, just, get done. There are no variables that hold values that get added to and saved, there are just rules that say how to do stuff.

You can see from this that prodecural languages have a state. Values that are stored and have a value that changes as the state changes. You can trace them as they work their way through. Functional languages just exist, they execute and the result is found from the defined rules. Its brilliant, and a little worrying. You have to get the rules right, and you have to do things without storing a "state".


Making the switch

Ok, for people who are a bit long in the tooth and short in the hair (is that a thing?) who have been coding happily for 36 years in a procedural language (not a figure picked from the air), it can be difficult to be sure functional code is going to always be able to do the job. It just seems to be a struggle. But remember, we are coding for money here. If something doesn't do what we think it will do people lose real money, maybe a lot. Not just a bit of software not working for an hour... real lost money. There are too many examples of holes being found in smart contracts which allow the funds to be drained to ignore this stuff.

So Plutus follows the rules of functional languages, and you have to think in the functional way. You have to think in a way that doesn't require storing a state, mostly, but you do have the blockchain. When the blockchain gets updated the data gets stored forever, so you can use it as an oracle (of sorts) to store and recover information, and you can depend on it completely. Define your rules, then follow them, check it does what you think, and use the blochain. You'll be fine.


Plutus

Plutus is not Haskell. Its a based on Haskell, but it knows what it is being used for. It doesn't have to worry about loading data from a database, or sending text to a printer, so it can concentrate a bit. While Haskell finds a value "when needed", Plutus calculates immediately. This makes it a bit more predictable. Also, it supports code that runs "on-chain" and also "off-chain". When you are coding a smart contract you will write rules that define what the user will see on the screen, and what they are allowed to do, which is what I mean by "off-chain". And then what will happen to the money when particular requirements are met, and how long to wait, before using different rules, is what I mean by "on-chain".

Plutus is a pure functional blockchain programming language. Its purpose is to allow clean verifiable code to be developed, and to make silly syntax errors impossible. But at the same time it has to be possible to convert other languages into Plutus. It has to be complete. The plan is to compile all the other languages supported by Cardano, including Solidity, into Plutus. So we can't have any gaps.


Marlowe

Marlowe is a much simpler language. The premise is that most financial contracts are simple, so a simple language is easier to understand and less likely to have bugs. I suggest you try Marlowe before you start experimenting with Plutus. Right now, there is a free Marlowe course on Udemy. I suggest you run through that, it explains Cardano, Blockchains, and Marlowe as well.

However, for more from me, check out my introduction to Marlowe page.


Testing on Plutus

Its easy to get started, just go into the Plutus Playground and read the instructions. You can play immediately using a web based test environment then when you feel confident you can either download the full environment from github or download a docker image which comes with everything installed to be run locally.

But a couple of things are worth knowing. First, Plutus isn't live in Cardano yet, it will be released in the Goguen phase, which comes after Shelley. So its testnet only. Second, you really need to learn Haskell if you are going to thrive. I'm no expert, but I have found this youtube video a good start for getting a feel, then followed by this website for a great walkthrough to take you step by step through the learning process, if you are starting from scratch.


This website was created by Kevmate. Its all my own work. Contact me by emailing me at kev@kevmate.com