Smart Contracts Fundamentals — Cryptoverse Wars — Intro Module

Abhinav Pandey
BUIDL Labs
Published in
7 min readOct 10, 2020

Why read this?

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?

Smart contracts exist across a distributed, decentralized blockchain network. Therefore it is important to understand — 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:

“Smart contracts are simple agreements”:

  1. 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:
  • (i) If it rains => you get to keep the $100.
  • (ii) If it doesn’t rain => then you have to give $100 to your friend.
  • This agreement is the equation above.

2. The contract encloses the agreement between you and your friend that both you will not cheat if the bet doesn’t go your way.

“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.

“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")
else:
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)
else:
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.

Want to learn how to write smart contracts and deploy it on a blockchain?

You have come at the right place. This series of articles are a write-up on Cryptoverse Wars “Cryptobots vs Aliens” — an interactive code school that teaches you to write smart contracts in SmartPy. SmartPy allows you to code DApps and deploy it on Tezos blockchain.

Prerequisites for the course

The course only expects you to be familiar with the following:

  1. You are generally familiar with software development, writing code, and running your code.
  2. You have working knowledge of Python and its basic concepts.

What will you build or #buidl?

In the previous chapter, you got a magical gem that gives alien-killing cosmic superpowers to any cryptobot!

Your mission is to build and assemble your cryptobot from scratch and then use the gem to power it in order to stop the incoming alien invasion!

To build the alien-killer cryptobot, you are going to learn to write a basic Cryptobot smart contract that will contain all defense and offense functionalities to blast aliens off in style!

By the end of lesson 1, your Cryptobot will:

  1. have the ability to move around to hunt for aliens!
  2. have the ability to shoot plasma bullets to kill aliens!
  3. have the ability to record alien kills for post kill analysis!

In later lessons, we’ll learn to add more functionality to your cryptobot like ability to use special moves that can blast multiple aliens in single fire, the ability to trade your cryptobot with other #builder-s on the planet etc.

Okay back to studying.

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:

tz1Syu3KacZ8cy4286a4vaCeoMtwqVKHkaoj

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?

Answer: XTZ is the currency used on the Tezos blockchain

Want to learn by doing?

Our course is meant to be consumed in such a way that you learn by doing. We have a content + coding interface so that you won’t have to continuously change tabs while you are busy learning :)

Our code editor. It is an invitation to get your hands dirty!

You can head over to our code editor to try it on your own! It allows you to attempt the quiz again and again so that you actually implement what you learn.

This is just the beginning. There are still challenges to be solved and fun to be had. And we would love to have you onboard.

What to do if I get lost and need help?

No worries!

If you need help, you can either:

  1. Open a new issue on project’s Github.
  2. Contact us on our support Telegram channel.

Originally published at https://cryptocodeschool.in.

--

--

Abhinav Pandey
BUIDL Labs
0 Followers
Editor for

Solving growth problems @BUIDLLabs