What is a Smart Contract ?

What is a Smart Contract ?

Lets deconstruct the Basics of Smart Contract

We all know the the blockchain is permission-less

The basic idea of a designing a permission-less system was, to remove dependency on permissioned intermediators as we had in a centralized environment.

But when there is no intermediator, then how do we build trust between two parties involved in any transaction of money/information.

That's where smart contract come in to picture.

Smart contract brings element of trust in a peer to peer transaction.

Smart Contract holds the business logic ( code written in a programming language ) that defines set of conditions that must be fulfilled in order to complete a transaction on blockchain.

Since there is no human involved and this piece of code(i.e. Smart Contract logic) is open for anyone to access, then it is guaranteed to get the desired outcome.

So, the smart contract can be defined as:-

Smart contract is a self executed piece of code (business logic) and data(state), that gets executed when certain conditions are met.

e.g.

The most popular analogy to understand a smart contract is a vending machine.

A Vending machine:-

  1. Stores the logic : A vending machine stores inbuilt logic :
    Item A = amount x Item B = amount y

  2. Validates the transaction : The moment you put a coin, the first thing vending machine does it to validate, weather the coin provided by you is valued same as item or not ?

  3. Executes : If the validation is passed, the item is dropped by the vending machine, otherwise the appropriate error message is displayed.

A smart contract works in the same way, smart contract is piece of code and data that exists and runs on blockchain forever once it is deployed.

Every smart contract can be accessed by anyone through it's address, like we connect with others using their ETH address.

E.g. : You can check the CryptoPunk's Smart Contract here

Whenever we make a transaction, the first thing that smart contract does is to validate.

Once the transaction is validated, it gets executed.

So this was all basics you need to get started with the Smart Contracts.

PS : I write about my Web3/Web2 learning experience here, if you loved this, please follow for more such content in future.

This post is created with ❤️ by Shivam