James Bachini

Smart Contracts Simply Explained

SMART CONTRACTS

This article is derived from a chapter in the free eBook explaining DeFi technologies:
DeFi Demystified | An Introduction To Decentralized Finance

Decentralized finance is built on smart contracts. The code that enables users to lend, borrow and swap tokens is all run on Ethereum’s virtual machine.

Smart contracts are written (mainly) in the language of Ethereum known as Solidity. It’s a statically typed language designed around the Javascript syntax making it familiar for web developers. We are also starting to see emerging alternate blockchains such as Solana and Luna which use smart contracts composed in Rust.

Smart contracts can’t be changed or fixed after they have been deployed to the Ethereum network.This means there is no room for bugs making it more like hardware development than traditional software coding.

For this reason they tend to be as simple as possible with existing audited code being imported and reused where possible. You can create a standard token in less than 10 lines for example by importing an existing template and providing some variables for the name, ticker and minted supply.

Here is a very simple hello world Solidity smart contract.

contract MyContract {
  string public myStateVariable = 'Hello World';
}

This can be deployed to store any string of text on a public blockchain. When deployed the contract will be given an address which can then be used by anyone to access that data.

A smart contract address is like the post code of a smart contract on a decentralized network. It maps to the memory address of the executable code on the virtual machine. When we want to interact with a contract we often need the contract address. A common example of this is a token address which describes where to find that token contract.

Those four lines of code alone have some powerful use cases. Once deployed no one can remove the text, no one can change it, it will live in the Ethereum blockchain for eternity.

DeFi smart contracts build on this concept to create applications to provide financial services. Imagine if instead of storing text in our contract we stored a ledger of funds of who owned what, who owed who and stored funds for collateral within the contract itself.

Smart contracts quickly became interconnected within the Ethereum ecosystem. They have been described as the lego bricks of internet money.

smart contracts connect together like defi lego bricks

In DeFi terms composability is the potential for smart contracts that form the DeFi protocols to interact with each other. A contract might connect to a lending platform to take out a flash loan and then use those funds to interact with an automated market maker to swap tokens for example. This interoperability between contracts has helped DeFi evolve to a complex interconnected network of financial applications.

“The next killer app is not the notes, it’s the links – Uniswap, Decentralized finance, etc. Every application is a component the future ecosystem can gain from.” Vitalik Buterin

If you would like to know more about building smart contracts then check out the Blockchain Developer Roadmap


This article is derived from a chapter in the free eBook explaining DeFi technologies:
DeFi Demystified | An Introduction To Decentralized Finance


Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.


Posted

in

, , ,

by