What is a Smart Contract?
![Source: Wikimedia Commons](https://cimg.co/w/guides-attachments/1/609/5323387be8.jpg)
Smart contracts are often mentioned in conjunction with blockchain. With the advent of blockchain 2.0 (which is when blockchain gained its first use case aside from Bitcoin in 2014), smart contracts have been an invaluable addition to the technology. While highly technical in nature, they do not have to be difficult to understand.
In this guide, we will take you through the basics of smart contracts. You will learn what they are, how they work, where they’re applicable, and even the basics of writing one.
What Is a Smart Contract
In the simplest sense, smart contracts are just a programmed version of your usual contract. Its purpose is to automatically trigger a previously settled-upon contract when all the preconditions have been met. Since every condition has to be manually programmed to execute, this can significantly reduce the amount of fine print designed to favor one party, even at the expense of the other.
Although smart contracts, as we refer to them now, rose to prominence with programmable blockchain implementations, they are much older than that. Computer scientist, lawyer, and cryptographer Nick Szabo first proposed smart contracts as a concept in the 90s. He described them as “a set of promises, specified in digital form, including protocols within which the parties perform on these promises.” Outside of their current implementations, smart contracts are present elsewhere: vending machines are considered a rudimentary version of the technology, as they follow the general principle that with the right input, a certain output is guaranteed.
Despite their name, smart contracts are not necessarily a valid, binding agreement in the eyes of the law, the way traditional contracts tend to be. However, in blockchain implementation, they don’t need to be. The interpretation by the US National Institute of Standards and Technology defines them as a “collection of code and data (sometimes referred to as functions and state) that is deployed using cryptographically signed transactions on the blockchain network.” This is also the definition by which Ethereum and similar blockchains operate.
For those who understand what blockchain is, it can seem obvious how smart contracts fit into the architecture of a blockchain. In a completely decentralized space, where nobody holds significant amounts of power, there is no place for intermediaries and third parties that handle compliance and consensus. As our aforementioned guide explains, consensus is reached through preset mechanisms that do not rely on human intervention. The same is true for compliance and execution of programs: smart contracts are programmed implementations of these concepts that remove the need for people to hold that kind of power.
How Does a Smart Contract Work
However, knowing what a smart contract is doesn’t necessarily explain how it works.
Most simply, smart contracts are made up of different functions that are defined on them. Users interact with them by sending a transaction that triggers a certain function. Each of these functions is defined in detail, so users can understand exactly what it is that they’re about to do.
The users of the network define smart contracts. Anyone who can code in the smart contract language can write their own, as long as they have enough native coins to deploy. The cost itself depends on the network you’re deploying on and its stipulations.
A real-world example would be a trade agreement. Once both parties have hashed out the details (what each is getting in return, the stipulations, any factors that might make them renegotiate the deal), they would usually find a neutral third party to ensure everything is done by the letter. However, neutral third parties cost money—and they can’t always be trusted to remain neutral or simply not to try to gain their own advantage from the situation. The most simple solution would be removing this third party completely. But who will act as a mediator then?
This is why people have always preferred the neutrality that only machines can achieve. The current technological advances still don’t see machines having their own preferences and interests, so they’re often believed the best solution to these problems. In other words, programming a smart contract lets all parties involved hash out the details of the trade publicly and transparently (as smart contracts are unable to do something that was not explicitly coded in), thus preventing potential malfeasance. This also reduces overall costs, as deploying and later triggering a smart contract is relatively low compared to lawyer costs.
Smart contracts guarantee that everything will be done in the exact way that it was coded. As they’re not very complex programs, these codes can often be read and understood with some basic programming knowledge. This is important for keeping everything above ground and facilitating a good working relationship with other participants in the network.
What Can Smart Contracts Be Used For
One of the biggest advantages of smart contracts is that they can be used for virtually anything, as long as they can be programmed. Of course, some use cases are more common than others. Some of the best examples include:
- Digital identity: in a time of dubious privacy on the internet, there is a concern about what data you’re sharing with companies whose websites you’re accessing. This can be easily digitized through smart contracts, where it could share your preferences for content curation purposes without actually disclosing your personal information.
- Securities: the financial sector as a whole suffers from a lot of friction between different parties, especially when it comes to holding and trading securities. By automating everything through smart contracts, intermediaries could be removed completely. The program would then take over, paying out dividends and/or other automatic payments, managing liability, and streamlining the workflow.
- Loans and mortgages: these things are often the source of frustration for many. Implementing smart contract payments would mean bringing down the overall cost that usually goes to the third party, maintaining a beneficial interest rate, and ensuring there is no fine print that can be taken advantage of. Additionally, setting up automatic monthly payments can further simplify the whole ordeal for all participants.
- Supply chain: as one of the best-known use cases for blockchain, smart contracts are also invaluable when it comes to supply chain management. From inventory tracking to automatic updates to all concerned parties, implementing smart contracts can improve transparency and significantly reduce room for potential fraud.
- Escrow: as with other activities that require third-party involvement, escrow is also one of those that would benefit from automatization. With smart contracts, funds are held in a safe location until all conditions for their release have been met. This can almost eliminate the risk of theft and fraud while simultaneously keeping everything fully transparent and, perhaps most of all, affordable.
- Health systems: medical data is highly sensitive, and most jurisdictions have laws that protect it from unauthorized access. Using smart contracts can not only protect that data but also lets individuals decide who can get access to it. Ultimately, people could provide medical researchers with access to their data for a fee, eliminating a significant amount of ethical concerns for all parties involved.
- Salaries: businesses keeping salaried employees could save significant money by paying them out on an automatic basis. Even if they have to take days off into account, these changes can be tweaked quickly and easily. The concept could work on hourly employees as well.
The list of smart contract use cases is far from exhaustive. However, it serves only to showcase the wide range of applications beyond what many people think of when they hear about the technology. With the right infrastructure, smart contracts could go far beyond the use cases outlined here.
Benefits of Smart Contracts
Many of the benefits smart contracts offer to the way you do your business can be deduced from what we’ve shown by now. On the other hand, some go beyond what may be obvious at first. Let’s take a closer look at them.
- Trust: or, perhaps more accurately, trustlessness means that you do not need to implicitly trust anyone that the conditions you’ve set will be executed. As a smart contract has no autonomy of its own, you can rest assured that everything will happen exactly as it is written.
- Safety: cryptography, the concept upon which blockchain (and smart contracts, by extension) is built, keeps everything vastly more secure than many other technological solutions.
- Speed: using smart contracts is a significant step up from manually handling everything that can be automated. Especially in the case of intermediaries, which can take their time depending on their own practices, moving everything to smart contracts can be just the timesaver your business needed.
- Savings: going by the same logic as with the aspect of speed, removing third party interference also saves you the money you would pay for their services.
- Autonomy: not relying on intermediaries gives you more power to decide, by yourself or with another interested party, exactly what your smart contract should do. Additionally, the chance of someone erring (or even manipulating) is significantly reduced with fewer participants.
- Accuracy: unless a mistake is preprogrammed into the smart contract, it is physically incapable of doing anything other than what is written in its code.
- Transparency: not only will you be able to read the smart contract and see if it has been written in accordance with what you wanted or needed, but the fact that it is stored on the blockchain means that all the relevant data will also be visible for posterity. For businesses, this can speed up auditing processes.
- Ease of understanding (and use): it’s true that code can be written in incredibly confusing ways. However, high-quality code will be easy to understand and use, which means it will be far easier than poring over long, dense legal documents.
Other benefits of using smart contracts will depend on your personal use case. Most importantly, all of them have one thing in common: they make everything easier.
Potential Drawbacks
Of course, no technology is a panacea. This is especially true for blockchain and smart contracts. As they’re still relatively new and address long-standing problems across many industries, they’re often expected to be able to do much more than they realistically can. Here are some issues smart contracts may face:
- Not legally binding: in spite of their name, smart contracts are not necessarily actual contracts. They may not hold up in a court of law, but this may change on a case-by-case basis.
- Regulatory uncertainty: in the same vein, as the technology is so new, there are often no government regulations in place. Depending on the type of transaction, they might not be necessary—but they might also be critical, so navigating these legal issues can be a chore.
- Taxation: similarly, how do you tax-smart contract transactions? While some may have their precedent in traditional finance, the ascent of cryptocurrencies has brought some new factors into play.
- Addressing bugs: no code is perfect, and bugs happen, even to the best coders. Some of them may not be noticed until it’s too late, and transactions on the blockchain are irreversible. In other words, mistakes can be costly.
- Rescinding contracts: as smart contracts are quite literal, there is often no way to rescind them the way you would with a traditional contract, i.e., in court.
- Not everyone can read code: simply put, not everyone knows the basics of coding. While theoretically, smart contracts should be more straightforward than documents on paper, as they don’t permit fine print. However, if you can’t read the code, anyone can write anything they want with you none the wiser.
- They can’t get real-world information: smart contracts can’t access information from outside the blockchain because that might jeopardize consensus. So-called oracles are used to overcome this obstacle.
The importance of each of these drawbacks, just like the benefits we listed, depends on what you’re actually using smart contracts for. Still, being aware of these pros and cons helps make an informed decision if you’re looking into using smart contracts.
What Is An Oracle?
While talking about blockchain and smart contracts, we stated several times that the goal of both, among other things, is to eliminate reliance on third parties. However, there are some situations in which this cannot be avoided. One of those situations is when you need real-world information to feed into smart contracts without constantly looking for it manually.
Blockchain oracles are such third parties. They act as the link between on-chain data, which is the blockchain, and off-chain, or what we call the real world. This helps broaden the scope of smart contracts. Without oracles, smart contracts would only be able to operate with the information they can get from the blockchain itself, which isn’t a lot.
To keep the data from being manipulated, oracles are also often decentralized. This means that they’re all sending the same data, and the data that the majority sent is taken as correct. If an oracle is found to be very inconsistent with the rest too often, it can be presumed malicious and punished. There are many different kinds of oracles, and the type that is implemented will depend on what the network and its users need.
How to Write a Smart Contract
To write a smart contract, you will need to be familiar with at least one programming language used for this purpose. On the Ethereum blockchain, you have the choice of two developer-friendly languages: Solidity and Vyper. You will also need gas: the more complex a transaction in the smart contract, the more gas it will need. Each transaction specifies the amount of gas it is willing to pay to run some code, so the total fee paid comes up to the total gas used times the gas price.
How to write a smart contract will depend mostly on what you want it to do. The simpler it is, the quicker you can do it, even if your programming knowledge is pretty basic. There are myriads of tutorials online to help you get started.
The contract will have to be compiled before it’s deployed on the blockchain. Compiling will also help figure out if you’ve written everything correctly and if it’s working the way it should.
To learn more, you can refer to the Ethereum website, which holds many step-by-step explanations of how their smart contracts work!
Conclusion
As this guide shows, smart contracts are a way to automate things that would otherwise have to be done manually, with all the security, transparency, and immutability always offered by blockchain technology. While they have some drawbacks, smart contracts still solve genuine issues, which means knowing how to use one (and even write one yourself!) can be an invaluable skill. For starters, however, simply understanding how they work is an excellent starting point for the rest.
Have we missed something you wanted to know? Have any other suggestions about this entry? Let us know.