Smart contracts have emerged as a groundbreaking technology in Web3. These nifty lines of code revolutionize various aspects of decentralized applications (dApps) and enable seamless transactions of non-fungible tokens (NFTs).
But the power of smart contracts extends far beyond these use cases.
This beginner’s guide unravels how smart contracts work and explains their transformative impact.
What are smart contracts?
A smart contract is a coded agreement designed to automatically carry out a set of instructions, which will occur if and only if the proper conditions are met. These digital contracts are stored on the blockchain, making them secure, immutable, and trustless.
Let’s start with the words themselves. Forget “smart” for a moment, and what you’re left with is “contract”. In its simplest form, a contract is an agreement between multiple parties. This agreement can be anything, but usually takes the form of some kind of exchange.
For example, a rental contract is an agreement whereby a tenant exchanges money to live in a property. An employment contract is when an employee exchanges his or her services for a steady paycheck.
Contracts can come in verbal or written form, but there’s a catch: all contracts can be disputed, even when they’re signed and sealed. This is why there’s often a trusted third party in the middle that ensures the other parties fulfill their ends of the agreement.
For example, suppose you want to order food from MoonPizza. Now, this may not feel like a contract, but it is: you pay MoonPizza for food, which they deliver. You use an app, MoonFood, to get it. In this scenario, MoonFood is the trusted third party that ensures you pay and that MoonPizza delivers.
While this setup works, it comes at a cost (literally): both you and MoonPizza have to pay transaction fees for MoonFood’s services. This is where smart contracts come in.
Who created smart contracts?
Interestingly, the idea of smart contracts came about long before the blockchain.
The term “smart contract” was first coined in a 1994 paper by Nick Szabo, a computer scientist and cryptographer credited with developing one of Bitcoin's early predecessors, Bit Gold. Szabo initially proposed that smart contracts be used for things like fraud reduction or enforcing contractual agreements. It was only later, in a 1996 paper, that he proposed they be used for digital money.
The smart contracts we use today, though, came about after the creation of Ethereum.
Ethereum was the first programmable blockchain, meaning it introduced the concept of smart contracts to the world of decentralized applications. Unlike traditional cryptocurrencies, Ethereum's programmable nature allows developers to create and deploy self-executing contracts that automatically execute predefined actions when specific conditions are met.
This groundbreaking innovation opened up a whole new realm of possibilities, enabling the development of decentralized applications, tokenized digital assets, and decentralized finance (DeFi) protocols on a global scale for mainstream adoption.
How do smart contracts work?
Smart contracts use a mechanism known as ‘if this, then that’.
To illustrate this, let’s go back to our earlier MoonPizza example. A smart contract could be set up that ensures if MoonPizza delivers you food, then a payment will be made. At the moment, MoonFood is the one making sure of contract execution, but a smart contract automates this process and removes the need for MoonFood as a middleman.
But how? This is where blockchain comes in.
What is a blockchain?
To fully understand smart contracts, you need to know a little bit about how blockchain technology works. So here’s a quick explanation.
A blockchain is a type of distributed ledger used to validate and record information digitally. Distributed ledgers are databases that are spread across multiple peer-to-peer devices. All of these devices can access the data and make updates or verifications in real time, almost like a shared document.
Unlike a shared document, though, none of the information recorded on the blockchain can be changed or deleted.
How do smart contracts use blockchain technology?
So, an “if this, then that” is written as smart contract code on a blockchain. Then, the network of devices (nodes) on that blockchain carry out those instructions when their conditions have been met and confirmed. So, if the nodes get an alert that a MoonPizza delivery has arrived at your address, they will work to verify it and, if they do, the funds will be released. The blockchain is then updated to show that the contract has been completed and the smart contract is concluded and recorded.
Like all data on the blockchain, this record can’t be changed or removed once it’s been added, and it’s visible to everyone with permission to view that blockchain network.
Smart contracts can be as simple or complicated as necessary, as long as they use an “if this, then that” mechanism.
What are the benefits of smart contracts?
Beyond the immutability afforded them by blockchain technology, there are many benefits of smart contracts. Here’s a quick run through of some of smart contracts’ main benefits.
Accuracy, speed, and efficiency
Since the conditions of smart contracts are written into code, the contract is automatically executed once these conditions are met. This, combined with the fact that smart contracts are entirely digital, removes any requirement for paperwork that needs to be manually processed.
The result? A seamless, speedy, and error-proof smart contract that’s executed automatically.
Trust & transparency
Using blockchain technology removes the need for a trusted third party to verify and validate data. Instead, a decentralized network of devices fulfills this role, only validating an action or transaction once the blockchain network nodes have confirmed it.
Once a smart contract has been completed, the information is then stored on the blockchain, visible to all. This means there can be no doubt that a party has edited or altered an agreement for their own benefit, because the whole record is there for everyone to see.
Again thanks to blockchain technology, it’s incredibly difficult to hack a smart contract. This is because all blockchain transaction records are encrypted, requiring an enormous amount of processing power to decrypt.
Even if a party had that kind of processing power, the chronological nature of blockchain record storage means that it would have to alter the entire chain to amend a single record, and all of these changes would have to be validated by the other nodes in the network.
Smart contracts can save money. The acts of processing paperwork, verifying that certain actions have been taken, and contract execution are all costly. Smart contracts automate all these processes, removing that costs associated with them.
How can smart contracts be used?
Earlier we mentioned that smart contracts are mostly used for decentralized applications (dApps) and seamless transactions of non-fungible tokens (NFTs), but they have many more applications beyond Web3.
A perfect example of how smart contracts can be used in familiar situations is insurance. Currently, there are a lot of intermediaries to go through to claim insurance. Let’s use flight delay insurance as an example.
Say you purchase flight delay insurance for your MoonAir flight through MoonSurance . The contract terms of this insurance state that if the flight is delayed by 90 minutes or more, you’ll get the cost of your flight back.
You’re at the airport at 3.30pm, but your flight was meant to take off at 2pm. Now, you have to contact MoonSurance, who will have to confirm the delay time with MoonAir (who may also have to provide evidence), and will then have to contact their finance provider to release the funds back to you. Boy, that’s a lot of steps.
Now, let’s make it more efficient. Suppose smart contracts were used for the insurance payment instead. Same situation: your flight still hasn’t taken off by 3.30pm when it was meant to take off at 2pm.
The smart contract will instead use oracles such as Chainlink, a mechanism that connects smart contracts to external data sources.
Through oracles, smart contracts can be provided with external data such as flight times, that inform it of the flight’s delay. Since the smart contract is set up with the mechanism if flight is delayed by 90 minutes or more, then release funds, the cost of your flight is automatically released to you before you’re even on the plane.
No intermediary parties involved and no waiting weeks for a refund. Just instant transactions that get you your funds quickly.
Another example is voting systems. Using smart contracts for an election means no party can manipulate the data—it’s all recorded, visible to everyone, and can’t be changed.
Smart contracts could ensure that no false candidates get on the ballot, and that each voter can only vote once.
For any given crowdfunding project, there are three main parties: the project team, the facilitator (usually GoFundMe or Kickstarter), and the contributors. At the moment, Kickstarter works like this: a project has a goal and if that goal is reached, the funds are released to the project.
If the goal is not reached, however, the funds are released back to the contributors and the project doesn’t get anything. All of this relies on Kickstarter as the middleman to complete the fund transfer and say whether or not a project’s goal has been reached.
With a smart contract, however, Kickstarter’s services wouldn’t be needed. Instead, a smart contract would be written that says “if X goal is reached, then release funds to the project. If X goal is not reached, then release funds to contributors”.
What are the limitations of smart contracts?
While smart contracts are self-executing and self-verifying, mitigating a lot of human error, humans still have to write the code that enables this, and humans can make mistakes.
Poorly written code can feature bugs that pose two main risks. The first is that the smart contract could be rendered useless: if the code has bugs that cause it to malfunction in any way, the smart contract's execution will be at great risk and it won’t complete its job.
The second risk is that the bugs can make a smart contract vulnerable to attacks, which can result in parties losing a lot of money.
Even the best computer code in the world can’t account for humans changing their minds. With a traditional contract, updates can be made to the original – it requires a bit of paperwork (the two parties must sign an agreement, for example), but it can be done.
This isn’t the case a smart contract since the blockchain record is immutable. Instead, a whole new smart contract has to be written to interact with the original record in order to add or amend anything.
While this certainly has its uses, it can be time consuming and can create a whole host of vulnerabilities (more code means more opportunities to make a mistake).
Since smart contracts are still fairly new, there is a lack of clear regulation and governance. This creates a grey area for smart contracts. If something goes wrong, who is liable?
This is something that will likely become clearer with time, and some regulators like the EU are already acting.
Since there’s no human involved in the smart contract execution process to interpret the data, the terms and definitions must be made incredibly accurate in the smart contract code. If they are, the smart contract executes. If they aren’t, the smart contract either won’t execute, or will execute incorrectly – the consequences of this can be exceptionally damaging.
What is the future of smart contracts?
Smart contracts have a wide range of applications that are already being adopted. For example, video games company Ubisoft is using smart contracts to let users buy and sell NFTs. Dutch bank ING is using them as a trade-settlement system. Even the Swedish government trialed a blockchain-based land title registry using smart contracts for real estate transactions.
Smart contracts are poised to revolutionize industries across the board, unlocking vast potential for innovation and efficiency beyond our current imagination. It's only a matter of time before the world embraces smart contracts to streamline processes and establish a new standard for trust, transparency, and security, all in seamless and automated transactions.
Start using smart contracts
Now that you've learned more about how smart contracts work, it's time to start using them with your own digital assets.
Before you can create your own smart contract, you'll first need to possess the necessary cryptocurrency to perform transactions on the relevant blockchain network. Many smart contract applications run on Ethereum, making it one of the most popular digital currency choices for smart contracts.
You can buy Ethereum via MoonPay or through any of our partner wallet applications to get started with Ethereum smart contracts. Just enter the amount of ETH you wish to purchase and follow the steps to complete your order.
MoonPay also makes it easy to sell Ethereum when you decide it's time to cash out. Simply enter the amount of ETH you'd like to sell and enter the details where you want to receive your funds.