All of decentralized finance (DeFi) is powered by smart contracts. In this article, we’ll show you how they work.
🍒 tasty takeaways
Smart contracts are programs (code) that execute on a blockchain when certain conditions are met.
Smart contracts are like vending machines in they require no middlemen and use “if/when…then” logic.
Nick Szabo invented smart contracts in the 1990s, years before blockchain was invented.
Smart contracts work only with Turing complete blockchains, like Ethereum.
What Is a Smart Contract?
Smart contracts are programs that execute on a blockchain network when predetermined conditions are met. When transactions are stored on distributed ledgers, they become traceable, transparent, and immutable, which is another way of saying that they are impossible to alter.
Smart contracts are the building blocks of Web3, which is rebuilding the internet with Web3 apps known as decentralized applications, or ‘dApps’. The most popular dApps use smart contracts to power decentralized finance (DeFi).
At their core, smart contracts perform two very basic functions:
The sending of digital assets/cryptocurrency from one entity to another when conditions are met.
Penalizing a party for not following through with the predetermined terms.
The financial services sector is currently at the forefront of smart contract adaption. This industry is using smart contracts to replace manual processes that are both slow and expensive.
The main value-ad of smart contracts is that they automate processes that are typically performed by (often) costly intermediaries and middlemen.
🍒 New to Web3 concepts? It may help to start with a basic understanding of blockchain technology: What is Blockchain and How Does it Work?
How Do Smart Contracts Work? Vending Machine Analogy
Though creating a smart contract will require some coding knowledge, understanding how they work is simple. At their core, smart contracts perform very simple functions.
Nick Szabo, the inventor of smart contracts, compared smart contracts to vending machines:
So a vending machine is programmed to release (output) a quantity of product when a certain amount of money is inserted (input).
The vending machine model works because both the money and the product are stored in a ‘lockbox’.
Smart contracts act similarly, but instead of storing snacks on machines, smart contracts store code on blockchain platforms. The blockchain here is the ‘lockbox’. Like with vending machines, smart contracts will only be executed when certain predetermined conditions are met.
Vending Machine: If I put $1 in, then the machine will output 1 bag of chips. In the meantime, the machine will safeguard the deposited coins and inventory.
Smart Contract (in shipping): If the GPS coordinates of a truck reach the delivery destination, then the driver will automatically be paid. In the meantime, a blockchain network will safeguard the funds and the integrity of the smart contract, only executing if/when a predetermined event occurs.
Smart Contract Setup
A few conditions must be met before a smart contract can be deployed to a blockchain network. Let’s look at these steps next.
Two or more parties must come to an agreement on the outcomes of an event.
These outcomes are written into a smart contract.
The smart contract is sent to and stored on a blockchain network.
All nodes within the blockchain network retain a copy of the agreement.
If a triggering event occurs, the smart contract will self-execute.
Smart Contract Example: Crypto Trade
Upon sending this order to 1inch (which is a DEX aggregator), the protocol will create a smart contract that has within it the terms of the trade that you stipulated with 1inch.
As we learned before, smart contracts run on basic “if/when…then” logic.
In this scenario, the smart contract will not execute until ETH falls to a certain price (if), and ‘if’ it does indeed fall, ‘then’ the trade will be executed for the amount you specified.
History of Smart Contracts
Smart contracts were invented by computer scientist and cryptographer Nick Szabo in the 1990s, years before blockchain technology was created.
Here is how Nick Szabo, the inventor of smart contracts, describes the technology:
Though this was indeed a revolutionary technology, smart contracts initially lacked secure locations to be stored and executed.
Some twenty years would have to pass before the full utility of smart contracts would be realized. This came in 2015 with the release of Vitalik Buterin’s ‘Ethereum Blockchain Network’.
Ethereum and Turing Complete
Turing complete implies a system is capable of solving any mathematical equation, regardless of the complexity. Most modern devices (such as the one you are on), for example, are Turing complete.
Buterin believed that a blockchain could store more than just transactions. By incorporating Szabo’s smart contracts into the Ethereum Virtual Machine (EVM), he created a blockchain network capable of storing both transactions and code (smart contracts) in its blocks.
Every single application you use today (Facebook, Twitter, Netflix) is comprised of code that can in theory be carried out and executed via smart contracts on decentralized blockchains. When compared to traditional organizations that rely upon centralized servers for the saving of data, decentralized entities are more secure, democratic, and cost-efficient.
All smart contracts deployed on the EVM are written in Solidity, which is a programming language designed especially for Ethereum.
Here are a few other smart contract platforms that are Turing complete and their respective programming languages.
Solidity & Java
Multiple programming languages
Rust, C, C++
🚨 Though Bitcoin is not considered to be a Turing complete blockchain, it is able to support some smart contracts using its Script programming language.
Smart Contracts: Real-World Use Cases
Now that we have a better understanding of how smart contracts work, let’s explore some ways different industries are embracing this technology.
Smart Contracts in Logistics
The nature of supply chains is incredibly complex. There are a seemingly infinite amount of variables that must be manually accounted for.
Smart contracts help to automate historically labor-intensive activities in supply chains. MIT Libraries state that:
In supply chains, smart contracts allow for:
Faster (automated) payment
Greater supply-chain transparency
Faster resolution as all details are transparent
Smart Contracts in Real Estate
Anybody who has ever purchased a home knows the painstaking amount of paperwork and processes involved. Smart contracts can help to simplify these routine business processes in many ways.
One promise of smart contracts in real estate is the tokenization of properties, which uses smart contracts to convert a property’s value to a blockchain. Additionally, tokenized properties could be fractionalized, allowing anyone the opportunity to be a partial owner of a property.
Wide-scale adoption of tokenized homes, however, may take some time. Here are a few more practical ways smart contracts may be used in real estate in the coming years.
Transferring property ownership
Fundraising for large developments
Income collection for rental properties
Smart Contracts in Finance
Smart contracts are the perfect fit for finance, an industry bogged down with labor-intensive manual processes.
Here are a few ways smart contracts are being utilized in the trading industry alone.
Immediate trade settlements (currently takes days)
Tokenization of equities, allowing global access to any stock
Automated trade executions
Immediate resolution of margin calls
And here are a few more ways smart contracts are helping to make the banking industry more efficient.
Automation of the loan process
Faster international transfers
More effective fraud detection
More transparent and accurate financial reporting
Smart Contracts and Gas Fees
Smart contracts are executed on blockchain networks. Like all transactions that are executed on public blockchains, the deployer of a smart contract must pay ‘validators’ a fee for doing the math required to store their smart contracts on immutable blockchains.
Gas fees fluctuate widely and are mostly determined by supply and demand and the number of validators operating. The gas fees for simply buying and selling crypto are usually a couple of dollars. The gas fees for smart contracts, however, can range from a few hundred dollars to tens of thousands of dollars for more complex smart contracts.
Smart contracts offer profound utility to both centralized and decentralized organizations. The efficiency they introduce is hard to ignore, and it is difficult to imagine a future where they do not play a significant role.
Of course, there are downsides to smart contracts as well, particularly for those workers whose jobs this technology will render obsolete.
On the flip side, companies that embrace blockchain technology and smart contracts may have more free cash. This may prompt them to raise other budgets, such as R&D, which would create more jobs.
Smart contracts are a set of rules that two parties agree upon. When a triggering event occurs, a smart contract self-executes on a blockchain the terms set forth in the predetermined agreement.
Bitcoin is a non-Turing complete blockchain so it is incapable of storing smart contracts.
The main point of smart contracts is that they provide an effective way of verifying, enforcing, and executing predetermined conditions set between two parties.
Regular contracts rely upon both centralized institutions and trust while smart contracts are decentralized and trustless. Additionally, smart contracts execute automatically while regular contracts require intermediaries.