What is a smart contract?
Smart contracts make life easier by putting a contract into code. It’s impossible to lie, and every single action taken with the contract are public and verifiable. Simply put, a smart contract is a piece of code on the blockchain that can only do what it is programmed to do — which is to execute the contract. If the code is fair, the contract is fair.
Let’s start with an example of a contract where a smart contract makes an interaction smoother.
In this example, you want to crowdsource funding for a startup idea you have, but you need 10k to get it off the ground. If you raise sufficient money, you will start working and your investors will own part of the company. If you don’t raise the 10k you want to send the refund of the funds back to each investor. You enlist a third-party service to accept funds on your behalf from the public up to $10,000 for two weeks.
In this relationship, you’re trusting the third party to actually do what they say they will. First, you’re trusting that they won’t simply steal the $10,000 and that they will properly refund investors if you don’t raise a sufficient amount. You trust that not only will they do this, but that they won’t make any mistakes and accidentally send incorrect amounts to the wrong investor. Wouldn’t it be nice if you didn’t have to trust someone else to hold the funds or worry about human error? Instead, you could use a smart contract! The smart contract would hold the money and using “if-then” statements would properly handle the money in all situations.
Smart Contracts are “Automation Engines”
A smart contract is a piece of code that does something only if something else happens. They are self-executing digital contracts that contain the terms and conditions of an agreement between the parties involved. They are also called “ if this, then that” by many people.
The term “smart contract” was first used by Nick Szabo in 1997, long before Bitcoin was created. He wanted to use a distributed ledger to store contracts.
They are beneficial because they are immutable, transparent, secure, and fast.
Smart Contracts Are Immutable
Immutability means they cannot change. See the picture with the person using a whiteout pen to edit a smart contract? That’s not possible. Once a smart contract is deployed (sent to the blockchain to become publicly usable) it can never be changed. It will only do exactly what it was coded to do. Nothing more, nothing less. Do you remember how I said some people call them “if this, then that”? It’s because once smart contracts get triggered, they can only do exactly what they were coded to do.
Immutability is both a strength and a weakness. It is a strength because you can trust them. No evil villain can change the contract halfway through to manipulate things to their advantage. However, the weakness is that if they weren’t coded properly… they can’t be changed to fix unintended behavior.
So what happens if there is a bug or the code logic wasn’t written properly and it doesn’t accomplish what it was intended to do? Well, it will remain that way forever. The best solution, for now, is to create a new smart contract fixing the past contract’s issues and inform people not to use the old contract. This happens very often by the way.
Smart Contracts Are Transparent
Since all transactions through a smart contract are recorded on the blockchain, there is no need to question whether information has been altered for personal benefit. You can’t hire a lawyer and argue “that wasn’t our agreement”. These smart contracts are an agreement between the parties that are only executed if certain conditions are met and as public material, anyone can examine them.
Smart Contracts are Secure
Smart contracts rely on the blockchain for their security, and since each record on the blockchain is connected to a distributed ledger, hackers would have to alter more than half the nodes to change a single record. The blockchain is built so those previous transactions can’t be changed. You can add to it, but not change the past. What is done is done. This is great in settling arguments between people.
Smart Contracts Are Fast
Once the conditions for a smart contract are met, it is executed immediately. No waiting until the next business day, no holidays, no paperwork… it is immediate.
All the above reasons make smart contracts extremely powerful, but what do people use them for? To help you get the hang of it, let’s go over some examples of current use cases, with some potential use cases thrown in to expand your horizons for what smart contracts could be used for.
Getting a flash loan
Would you believe me if I told you that it’s possible to borrow a lot of money with no money down? Well, you absolutely can through the smart contracts! But only if the smart contract in question pays it back right after it’s borrowed. That’s why it’s called a flash loan.
But all of the money must be paid back, right? You may be wondering, why would we want to do this?
Imagine you could buy 1 MATIC for 1 dollar on Binance exchange and then sell it for 1,10 dollars on Coinbase exchange, which is called arbitrage. You could theoretically borrow the money to do this arbitrage transaction by writing a smart contract that pays it back in a few minutes with some interest.
So here’s the kicker: the smart contract could do all the work for you. It could check to see if the arbitrage would be profitable, check all the transactions fees, check to make sure it can pay back the money, and if so, execute the trade for you. If so, the smart contract runs the code and you can borrow those funds.
You could never do this with traditional finance, but you can on the blockchain. If you want to know more about flash loans, visit our post about them.
Insurance
Did you know that an entire insurance company can be created with just a few smart contracts? Imagine the following scenario: Farmer Tom from Missouri wants to protect his farm and his bottom line from the risk of a heatwave. So Farmer Tom gives an insurance agency 2,000 dollars in exchange for the promise that if it’s more than 95 degrees for 4 days in a row in the summer, the company pays Tom 100,000 dollars.
This is how insurance works, but the process takes time, paperwork, headache, and sometimes insurance providers can try and reduce the amount they are willing to pay through legal trickery. If instead a smart contract was used, Tom could be sure that he would get his money if the temperature is over 95 degrees 4 days in a row, and he would get it immediately. His crops would die, but he would be protected from financial ruin. The smart contract’s requirements would be fulfilled and Tom would get his 100,000 dollars insurance.
However, you might be asking, how does a smart contract, a piece of code, know what the temperature in Missouri is? With the help of something called Oracles.
Oracles are essential tools to any smart contract that needs real-world information not already readily available on the blockchain. Oracles package up this information and provide it to the blockchain in ways that smart contracts can use to fulfill their “if-then” statements. Oracles can get a bit confusing, and if you want to dig into it, check our post about them. Quality oracles will be essential to unleashing the full power of smart contracts.
Token Trading
When it comes to smart contracts, facilitating trades is a great example. In traditional finance, a broker is required. Once again, it’s that third party you have to trust and whose traditional methods require double-checking past transactions before allowing your money to “settle” or become available to withdraw. Smart contracts can make trades instantly and settle transactions instantly. Many trading smart contracts are already available (often packaged with a shiny user interface called a DEX) where you can trade one token for another quickly and cheaply without relying on a broker. These trading smart contracts are often called Automated Market Makers or AMM’s and rely on some pretty sleek math.
Using smart contracts for trading tokens opens up a whole new world for traders that want to get into a specific coin that isn’t currently on a major exchange. Instead, they use decentralized exchanges (built using smart contracts) to swap those tokens.
Buying a house
Imagine eyeing a house you’d like to buy, but to your surprise, the owner is not listing the house on a realtor’s website, he or she is selling it on the blockchain through a smart contract.
There may come a day where we can use smart contracts to buy and sell a house. Instead of going to the usual process that takes weeks — advertising the house, securing the funding, using escrow, getting insurance — you could just send an offer to the owner right on the blockchain and within minutes this person could accept or deny. If he or she accepts, you immediately own the house and the old owner immediately has your payment.
Since you’d no longer be relying on brokers, banks, real estate agents, and everyone else (who all want their fair share of the profits) you’d be able to save massively by cutting out large portions of the fees. The seller would turn a better profit and you’d get a better price. Imagine if you could buy and sell a house as quickly and easily as you can buy and sell a stock? Cool right? With smart contracts and the blockchain, that would be possible.
Conclusion
Smart contracts are a unique invention and extension of the blockchain to facilitate business. They are fast, precise, transparent, and can be used for many things we can’t yet imagine. We are still very early in this technology and in the DeFi ecosystem itself, so with hope and anticipation, we can look forward to future innovations that are inevitably coming. I hope you are very excited to be a part of it, as I am!
If you have any other questions about smart contracts, please stop by the KogeFarm Telegram or Discord communities, where you’ll always find someone willing to help you out.