Smart Contracts

Chamod Malintha
setublog
Published in
4 min readMar 23, 2019

What is a Smart Contract?

A smart contract is simply a computer code in the blockchain network. It is like the backend of a blockchain application. When nodes/ computers execute the smart contract, it will update the ledger. It is a pre-written code that can execute a bunch of actions. The smart contract is where all the business logic lives.

https://dzone.com/

In 1993, Nick Szabo firstly described this smart contract concept to the world. In that explanation, he compared a smart contract to a vending machine. In vending machines, we put our money and we get our work done. Similar to that in a smart contract, we pay money and execute the code and get the transaction done. A smart contract follows this marketing logic: “if this — then that”.

In “if this — then that” logic, the program in blockchain network (smart contract) run by all the nodes in that network. The constructor is going to run when we deploy our smart contract to the blockchain network. In other words, an instance of the contract gets deployed and it can be identified any time by its own address. Deploying a contract to the blockchain is also a transaction which sealed by a hash. In Ethereum world to write the smart contract, we use solidity mainly apart from that we can use languages like python as well. When we compiling the code using solidity compiler, we receive compiled code and ABI (Application Binary Interface). We use this ABI to interact with the smart contract.

let me explain it furthermore by using some real-world examples.

1. Buying a car:

Real life scenario: when you are buying a car, you search it online and find your preferred one. Then you contact the dealer, ask further information. After that, you go to the bank, pay the dealer, do the paperwork and get the car.

But the thing is, in real life, this takes a couple of days maybe weeks.

By a blockchain system, all the car ownership and vehicle details can store in the blockchain network and when you place an order, it automatically executes the functions in the smart contract. At the same time when those are executed, the vehicle ownership and all the information related to that automatically assign to you. Then it updates those details to every node in the blockchain network, so everyone knows that you are the owner of that car and they hold a proof about it.

To do all these things it costs only a few minutes and also you do not need to waste your time in bank queues because, in blockchain world, you pay for everything by cryptocurrency.

https://www.toshblocks.com/ethereum/smart-contracts-blockchain/

2. Small Business (4 people invest money in joint investment and return interest)

The smart contract for this scenario could be programmed on the blockchain to take that interest- divide into four according to their investment ratio and send those amounts to the cryptocurrency wallets of each stakeholder accordingly.

That deployed instance of the code cannot be changed and if you need to change or make some update to that you have to pay some money (to programming company) then update the contract. Every change they make costs gas. But it will hold a proof about the update. Because every modification you do in a blockchain network is also a transaction.

Smart contracts are decentralized. That means they are distributed all across the network. So unrecognized parties can do transactions with each other without knowing any details about them. After the transactions, they do not need to stay in contact with each other at all because the blockchain network holds all the transaction details.

https://www.coindesk.com/information/ethereum-smart-contracts-work

Features of SMART CONTRACTS

  • Autonomy: you don’t need to rely on a middle person (like banks etc..) to make sure your contract processed as expected. Execution of all those stuff managed by network nodes.
  • Trust: Document details are encrypted in the ledger and managed by nodes.
  • Backups: all the transaction details/ document details are duplicated into lots of nodes. If one goes down it would not be a problem.
  • Safety: All the transactions secured by cryptography. (Ethereum uses Keccak-256 as their cryptographic algorithm)
  • Speed: you already know that this transaction system is much faster than existing ones.
  • Save money: By removing middlemen you can save a lot.
  • Accuracy: Smart contracts make no mistakes. Everything in a smart contract tests and validates before it deployed to the main network by using local environment and test networks(hope to discuss in the near future).

--

--

Chamod Malintha
setublog

Software Engineer | BSc. (Hons.) in Software Engineering | University of Kelaniya, Sri Lanka