Smart contracts can be hard to understand because they cover so many different applications. Because they are essentially just computer programs they can be used to do a lot of things. And the use-cases are expanding as more and more developers migrate to web3 and build more tools.
To try and understand what a smart contract is let’s start at the beginning…
Before there was a blockchain, back in the late 1990s, a developer came up with the idea of a self-executing contract, meaning that the contract would exchange the value of something between two parties as a computer program. But back in the 90s this was just an idea because there was no way to run an always-on distributed computer.
Today we have Ethereum. “Ethereum is a community-run technology powering the cryptocurrency ether (ETH)” and includes all the thousands of decentralized applications that run on it. The world wide network of Ethereum nodes make up the Ethereum Virtual Machine (EVM), which is a giant global computer that no one can turn off. This is perfect for smart contracts.
Law vs. Code
A smart contract is not a legal contract, but like a legal agreement (a deed for a house, the title for a car, etc.) a smart contract can coordinate the ownership of something from one person to another. Smart contracts replace legal contracts because they move digital assets from one place to another, where a legal contract can only command someone to move an asset.
Smart contracts are computer programs running on the EVM, so they work on the same basic mechanism of any computer program:
Inputs -> Computation -> Outputs
For programmers the internal computations of computer programs and smart contracts are very important, just as the fine print on a legal contract is very important for lawyers. But for the rest of us what we care about are the inputs and the outputs.
Apples and Oranges
Let’s say you and I sign a contract that dictates every time you give me an apple, I will give you an orange. This works great until I don’t give you an orange. Now what? Well, you can take me to court and, assuming I have an orange, the legal system will force me to give you one. If I don’t then maybe I have to pay “damages” or there is some settlement we agree to. That’s a lot of effort because the only way to enforce it is very expensive lawyers and the court system, but at least you have some sense of a guarantee.
Compare that to a smart contract. If I want to create a way to exchange apple coin ($APPLE) for orange coin ($ORANGE) I will write a program that sends one $ORANGE to the address of anyone who sends it $APPLE. That will work until the contract runs out of $ORANGE, and you’ll never have to take the smart contarct to court because I was smart enough to program it to only stop accepting $APPLE once it runs out of $ORANGE. That’s much easier!
And because a smart contract is a computer program that lives on the Ethereum blockchain, you can’t turn it off. As long as there is a blockchain that program will be waiting to hand out $ORANGE.
Here are some examples of smart contracts:
- Uniswap – a decentralized exchange using smart contracts to allow trading of crypto and tokens
- Compound – a platform using smart contracts to create loans
- USDC – a cryptocurrency that is pegged to the US dollar (known as a stablecoin)
Warning: Hazard Ahead
In 2016 when the very first DAO, called The DAO, was launched. A DAO is a smart contract that let’s people pool resources and work together for a goal. Everyone was super excited about a decentralized way to invest together. But, there was a bug in the smart contract, and someone exploited that bug and was about to steal a bunch of the funds.
Once a program is on the blockchain it is immutable, meaning it can’t be turned off, and it can’t be updated. This means they couldn’t fix the bug. In order to prevent the loss of a millions of dollars of investment the Ethereum community decided to change the rules for the entire blockchain and include a new smart contract to give people their money back.
(This made some people mad because the whole point of a smart contract is you can’t undo it, so some of them split off into a whole new blockchain. This is known as the “hard fork” of Ethereum.)
Just like watching out for the fine print in legal contracts, we have to be careful of the code in smart contracts.
Understanding Via Snacks
The example most people use to explain a smart contract is a digital vending machine. You can reduce the idea of a vending machine to:
money + snack selection = snack dispensed
A vending machine removes the need for a cashier, and automates the interaction between the customer and the snack creator. Smart contracts do this as well. A smart contract, like a computer program, is about automating digital interactions.
So when you hear “smart contract,” just think about it as a program. It’s computer code that takes inputs, does some computations, and gives outputs.
Note: I looked at a LOT of videos and articles about smart contracts as I was putting this all together. If you want to dive just a little deeper this video from Finematics is great: