Understanding smart contract.

Smart contracts are one the hottest thing in the blockchain sphere right but it can be a little bit difficult to fully comprehend what they are.

Djegnene Penyel
5 min readDec 26, 2020

Imagine that you had the possibility of renewing your rent without needing a third party?

No seriously imagine that any contract or agreement that you have made at this point in your life could execute itself without the need of third parties. Imagine how much easier it would be to create and implement a contract or agreement.

What if I tell you that a new technology called blockchain could allow you to do exactly that.

You might still be skeptical, but I guarantee you that it is true. Blockchain allow the implementation of smart contracts which are contracts that can execute without the need of any third party, and giving the fact that they are built on top of the blockchain they are extremely secure and no one can change them.

This article will explain what is a smart contract. It will also explain Ethereum and its virtual machine.

But what is a smart contract.

Smart contracts are one the hottest thing in the blockchain sphere right now. But it can be a little bit difficult to fully comprehend what they are.

To make it simple, a smart contract is technically the same thing as a regular contract. The only difference is that a smart contract is made of a collection of code (i.e function) and data (i.e state) instead of ink and paper. The other difference is that a smart contract executes, control, and document relevant events according to the rule of a given contract or agreement without the need of third parties.

Vending machine the oldest implementation of smart contracts.

Smart contracts work in the same way that vending machines work.
For example, if you buy a drink from a vending machine the vending machine does not need any third parties to execute the transaction, it only needs to follow the code implement into it to successfully execute the transaction. The transaction may go as follow, you put an amount of cash inside the machine and choose the drink that you want the machine code through the code implement into it and if all the giving condition that need to be check to successfully execute the transaction checks the machine give you the drink if they are not the machine gives you your money back and print an error. All of that without the need of intervention from any sort of third parties.

def make_transaction(ammount){
if(ammount < item_price){
return "the ammount giving is not enough."
change = ammount - item_price
return item, change

The code above is an example of the code that could be implemented into a vending machine.

A blockchain is usually built on top of a blockchain this makes it able to use some of the characteristics of a blockchain which allows it to be secure and immutable.


How a smart contract is added to the blockchain.

The creation of a smart contract is similar to a transfer of value in a blockchain or in other word making a transaction. The deployment of a smart contract on a blockchain occurs by sending a transaction from a wallet to the blockchain. The transaction includes the compiled code of the smart contract as well as a special receiver address. The transaction has to be included in a block. The block will then be added to the blockchain. After being added to the blockchain, the smart contract will execute to establish the initial state of the smart contract, and will then be able to execute itself without the need of any third parties. After posting a smart contract on the blockchain you can not change it and you can interact with it through transactions.

If you want to know more about Blockchain and some of its underlying concepts you can see a past article I made.

Ethereum and smart contracts.

As I stated before, smart contracts are usually implemented on top of a blockchain. One of the most well-known and use blockchain for the implementation of smart contracts is the Ethereum blockchain. Ethereum was first proposed by Vitalik Buterin, a cryptocurrency researcher and programmer as a world programmable blockchain. To allow it to be programmable the Ethereum blockchain Ethereum as incorporated into its blockchain two fundamental elements which are a virtual machine that can run an almost full Turing programming language and a gas system.

Ethereum and its EVM.

The Ethereum virtual machine commonly abbreviated to EVM is an essential piece of the Ethereum protocol because it allows anyone to execute code in the trustless environment that is the blockchain network.

Smart contracts are made with higher level programming langue but they are compiled into what we called EVM bytecode. This process is similar to the way normal compilers make binary files from a given source code.

How EVM work.

As we explained above, smart contracts are made with a high-level language before they can be compiled into bytecode that will be executed by the EVM. Even though there is a multitude of high-level programming languages that can be compiled by the EVM the most popular is solidity.

The code below is a simple implementation of a smart contract in solidity.

pragma solidity ^0.4.15;contract hello{
string public message;

function hello(string initialMessage) public {
message = initialMessage;

Gas and computation.


Gas is like a fee. Every transaction made on the Ethereum network needs a fee attached to it. This fee is paid in the form of gas. It is a unit that Ethereum used to determine the amount of computation power that will be needed to execute certain operations. Gas can be compared to the reward that miners get after mining a block in Bitcoin. In fact, miners are rewarded an amount in Ether equivalent to the total amount of gas it took them to execute an operation.