Lesson: Introduction to SmartPy

Ask Question

Chapter 2

Quick primer on blockchain & smart contract concepts


Before we kick start writing code, this chapter serves as a helpful primer to quickly ramp up why blockchain and smart contracts are game changing technologies!

Buckle in for this is a long chapter, though we try our best to blow your mind through explaining each technologies usecase more than how they work under the hood.


Readers who are familiar with these concepts can feel free to skip to the next chapter!

Why read this chapter?

We hope to provide readers with a convincing argument as to why combination of smart contracts and blockchain technology is going to revolutionize how humans cooperate between themselves 🤝

We have also embedded links to books/videos/blogposts that were helpful to us when we started our learning about these concepts.

Readers who are familiar with these concepts can feel free to skip to the next chapter.

What is a blockchain?

At some point in your life, you would have kept a track of:

  1. The money that you are earning (i.e income)
  2. and where are you spending it (i.e expenses)
  3. to figure out whether you have money left over (i.e savings) to buy your favorite things!

You can imagine a table that has rows that keeps logs of transactions. These tables are conceptually called ledger’s.

Some real world examples:

  1. Record books used by accountants that record business transactions.
  2. Property Registry which keeps track of who owns the house that you live in
  3. Your bank account statement which records your personal transactions.

At their most basic level, blockchains are digital ledgers.

We have ledgers in the real world, why use a blockchain?

The problem with the current ledgers in the world is that they are usually maintained by a person/institution (third party) which leads to an inordinate amount of trust put upon one person/institution.

An example of this problem is that you rely on your bank and hope that these guys won’t change/empty your account with your hard earned money!

Ever wonder why do you need a bank in the first place?

You use a bank primarily for:

  1. Saving your hard earned money.
  2. Transferring money to your friends and family as well as to buy things.

What if you can do all this, without needing the bank?

That’s where blockchain come in whose fundamental usecase is to maintain a single ledger without relying on a single trusted third party.

How blockchains work under the hood is out of scope of this course, though we recommend reading through the following 101 resources:

  1. Blockchain for Dummies - A Simple Blockchain Explanation for Everyone
  2. Blockchain Expert Explains One Concept in 5 Levels of Difficulty | WIRED
  3. How Does Blockchain Work?

Examples of blockchains include:

  1. The Bitcoin blockchain - on which the Bitcoin cryptocurrency runs on.
  2. The Ethereum blockchain - a global, open-source platform for decentralized applications.
  3. The Tezos blockchain - a global open-source platform for assets and applications backed by a global community of validators, researchers, and builders. This is the blockchain on which you are learning to deploy apps on through this course!

What are smart contracts?

Smart contracts are simple agreements written in code which are stored on the blockchain.

That’s a lot to take in, let us break it down:

  1. “Smart contracts are simple agreements”:

    • A bet between friends is a perfect example of a simple agreement.
      • Let us say you decide to bet $100 with your friend that tomorrow it will rain.
      • 2 possible odds:
        • If it rains => you get to keep the $100.
        • If it doesn’t rain => then you have to give $100 to your friend.
      • This agreement is the equation above.
    • The contract encloses the agreement between you and your friend that both you will not cheat if the bet doesn’t go your way.
  2. “Written in code”:

    • The contract like the bet shown above is a simple if..else program.
    • The smart in the word “smart contract” arises from the logic inducing capabilities of the contract.
  3. “Stored on the blockchain”: the blockchain acts as the database that stores them securely.

The best examples of contracts are found in the law and legal industry for eg:

if (found_guilty_for_robbery): 
    print("Verdict: Jail for 5 years")
    print("Verdict: Release the person")

What are some use cases of smart contracts?

Some popular use cases are:

  1. Insurance like contracts: imagine if a cyclone hits your area, and your insurance money starts coming in your bank automatically - without requiring any calls or interventions at your end!
  2. Decentralized finance: re-imagining the current finance industry to a more trustless and decentralized version. Imagine a farmer in India can take a loan from person in USA without both of them even knowing each other, let alone trusting each other.
  3. Prediction Markets: love betting? Stake your bets in a global betting market to predict events!

Why (smart contracts + blockchains) == game changing technology?

In banks, the system at a very fundamental level comprises of:

  1. The ledger a.k.a the record book that maintains how much money you have, your parents have, and all the people who have an account in that bank.
  2. The transactions between people i.e when you transfer money to your friend.

If you want to replace the bank with a complete software protocol which doesn’t rely on any trusted third parties, you can do it by:

  1. Replacing the ledger with a blockchain.
  2. Replacing the transaction system with smart contracts.

A transaction where I send $100 dollars to my friend in pseudo code would like the following:

 if(my_account_balance >= 100):
     transfer_money_to(friend_account, 100)
     print("Insufficient balance")

It may not sound a big deal until you focus on the part where you don’t need to rely on any trusted third party to manage and maintain this system.

Imagine all the big banks buildings in the world are now equivalent to a software protocol. That’s game changing.

What are accounts on a blockchain:

The blockchain is also made up of accounts which are pretty similar to real world bank accounts.

In the Tezos blockchain, an account has a balance of XTZ (the currency used on the Tezos blockchain), and you can send and receive payments in XTZ, just like your bank account can wire transfer money to other bank accounts.

Each account has an address, which you can think of like a bank account number. It’s a unique identifier that points to an account on the blockchain and it looks like this:


Quiz Time:

To get used to working with editor + also verify that you read the above chapter, can you answer the following question?

What is the name of the currency that is used on the Tezos blockchain?

When you’re finished:

  1. Click on “Check” to check your submission with the correct answer.
  2. Click on “Show Answer” in case you get stuck.