Teʒos SmartContract - 101
Let the journey begin with Teʒos SmartContracts
Let’s begin the series of the blogs where I’ll be sharing my knowledge/learning of the Tezos SmartContracts.
Now, I know that all of you know about the blockchain and the smartcontract; but still let me start with the basic introduction of those.
— Don’t stop reading here 😝 —
What is Blockchain?
The simplest answer to this question is, it is a chain of blocks where each block holds some information and linked together; and root block can be traced back using this link.
Blockchain = Block#1 + Block#2 + … + Block#nThis chain is distributed and shared among the nodes of a computer network.
As described above the main component in the blockchain iiisssss - BLOCK
Block contains the data about the transaction and the each block is connected using the hash.
Let’s see how,
Here Block #0 is called `Genesis Block` which is generated when we initiate the chain.
What is wikipedia is telling about Blockchain?
What is SmartContract?
Now that we have seen what is the Blockchain, let’s see what is SmartContract.
As name suggests, it is contract but Smart one 😎
They are essentially computer program that is self-executing. Terms of the agreement between different parties are directly written into lines of code, when met the smart contract gets triggered and executed. The code and the agreements exist across a distributed, decentralised blockchain network. The code controls the execution, and transactions are trackable and irreversible.
What is wikipedia is telling about SmartContract?
Now that we have cleared/refreshed our understanding on Blockchain and SmartContracts, let’s start with the real meat, which in our case is Teʒos
Now you must be thinking that, there are several blockchain solutions available in the market then why we are sticking to Tezos?
Big Question — WHY Teʒos?
It is an official blockchain of Manchester United — I thought this would be enough for the answer but I am wrong, right?
Tezos good range of features including:
Self-Amending Network
This is the way to upgrade the network without hard-fork.
The entire process is broken down into 4 stages:
Proposal Period
Exploration Vote Period
Testing Period
Promotion Vote Period
On-Chain governance
All Tezos stakeholders can participate in the governance, where each can vote and reach agreement on proposed protocol amendments
Delegation
A security deposit is required to participate in the consensus process. The consensus process relies on an honest majority for its security and thus will penalize any dishonest particpants to the point of losing their deposit. But, will be rewarding to honest behavior.
Baking
Baking is a process to sign and publish the blocks to the Tezos blockchain. Bakers validate all the transactions and add them to the blockchain in return they rewarded with additional XTZ. Baker will also get penalised, lose the security deposit and stop participating in the network, on acting dishonestly.
TPS:
Tezos To Reach 1000 TPS With Upcoming Octez v13 Release
Now let’s come to the main point, how to write SmartContracts
Michelson, SmartPy, LIGO & Archetype are the few languages to write the smartcontracts out of which SmartPY and LIGO are the most famous ones.
Let’s now start writing our first smartcontract writing using SmartPy 🧑🏻💻🧑🏻💻🧑🏻💻
SmartPy language is available through a Python library for building and analyzing Tezos smart contracts. If offers the online IDE to write and deploy the smartcontracts
Let’s create contract to store the `seed` and `random_value` in form of map aginst the `sender’s address`
Here you can find the full contract → contract
Now let’s try to undetstand the contract in bit details
most of you know what is this for, but still let me brag, we are importing the smartpy library and assigning an alias `sp` for further use
here, we are creating the contract class named `Tezos101` and then initialise the contract’s storage with empty variable named `storage`; where the type of the `storage` is map(string, string)
`@sp.entry_point` is an annotation for the contract methods which needs to be called from outside
`setValues` is such a method which can be called, by passing the values; which then accessed using the `params` variable
`sp.set_type` is kind of a stopgate method, which checks for the data type integrity
`self.data.storage[sp.sender] = params.value` is the the place where we add the value in the storage
I guess this self-explenetry and no need for any further words; but in one line this is being used to test the contract that we have created
Click on the `play` button and your contract gets executed
on execution you can see the output something like this,
Cool, yeahhhh…
And now I am sensing that your brain has already started giving signal to stop reading and switch to Netflix for Stranger Things - 4; don’t worry mine too 😀
So, let’s say this is for 101 and stay tuned for the next one where we start learning LIGO, as that is used when you have to write some complex contracts; but that is for the next time…
Till then stay safe, stay healthy ! Ciao !!!









