Smart contracts explained
Whenever someone buys a house, begins a new job, or purchases a candy bar, a contract is created between the two (or more) parties involved in the exchange. This contract defines and records the terms of the transaction, denoting the required actions of each participant. For example, if you give the cashier a dollar, the cashier must give you the candy bar. A standard contract’s sole purpose is to define these terms.
Alone, a standard contract has no power to enforce the terms that it defines. Instead, a legal or governmental third-party oversees the execution of a standard contract, ensuring that each party faithfully carries out their end of the bargain; if the terms are violated, the transacting parties must rely on this intermediary to rectify the broken contract.
However, thanks to recent advancements in distributed ledger technology, lawyers or other intermediaries are no longer required to oversee contracts. Using smart contracts, people can, for the first time, execute and enforce contracts without involving middlemen.
Smart contract origins
In 1994, legal scholar and computer scientist Nick Szabo envisioned a computer protocol which not only defined the terms of a transaction, but also completed the transaction itself. While standard contracts rely on lawyers or government agencies to enforce and execute the described exchange, these “smart” contracts are self-enforcing and self-executing.
To explain his idea more concretely, Szabo compared the smart contract to a vending machine. Imagine you want to buy a candy bar from the store. To do so, you have to fulfill a standard contract: you pay the listed price, and the store grants you ownership of the candy bar. Of course, this exchange does not happen on its own. A cashier is needed to execute the transaction and a legal body is needed to enforce it. For instance, if the cashier breaks the terms of the contract by accepting your money but then refusing to give you the candy bar, policemen or lawyers may be required to enforce the contract.
In contrast, vending machines complete all aspects of a transaction independently. When you want to buy a candy bar from a vending machine, all you have to do is select a product and input money. The machine verifies your payment, executes the transaction, and moments later you have your candy bar. Assuming the vending machine itself is secure, there is no need for a cashier, a lawyer, or a government agency. The transaction is atomic; meaning it should happen perfectly every time, or not at all.
Like vending machines, smart contracts fulfill an agreement without middlemen. Transacting parties simply agree on their terms, put a cryptocurrency coin into the program, and then the smart contract executes the desired digital exchange.
How do smart contracts work?
When Nick Szabo proposed them, smart contracts were infeasible given current technology. For smart contracts to function, they need a secure digital infrastructure which can reliably support intermediary- free transactions. In 1994, this technology simply did not exist. Now, due to recent advancements in distributed ledger technology (DLT) like blockchain and hashgraph, smart contracts are a reality.
Distributed ledgers are platforms which enable users to securely transact without the need for trusted intermediaries. In terms of the analogy, if smart contracts represent the software that executes a vending machine transaction, a distributed ledger represents the hardware of the vending machine itself. More specifically, the distributed ledger represents the mechanisms which take in currency, transport the product, and securely (but transparently) carry out the exchange behind tamper-proof locks and bullet-proof glass. While we won’t go into detail about how distributed ledgers work in this article, you can learn more by visiting "What are distributed ledger technologies (DLTs)?"
Distributed ledgers are uniquely suited to host smart contracts because they allow for atomic swaps. Atomic swaps are all-or-nothing exchanges. In other words, a transaction on a DLT will either happen precisely, or not at all. This functionality perfectly aligns with the goal of a smart contract: to define, self-execute, and enforce a transaction to the letter. By harnessing the power of atomic swaps, smart contracts can ensure that their terms will be followed correctly, or the entire transaction will be void.
Atomic swaps are transactions which are either carried out completely or not carried out at all. Smart contracts rely on atomic swaps to self-execute and enforce the terms of a transaction without requiring third-party oversight.
Over the last few years, smart contracts have grown and evolved. The computer language Solidity was developed specifically for smart contracts, granting developers tools to quickly build complex digital contracts. While Solidity was originally built for the Ethereum network, Hedera Hashgraph also supports the Solidity language.
Why are smart contracts useful?
Smart contracts’ primary advantage is their independence. Without middlemen, there is no need to pay middlemen. This can dramatically reduce costs for major transactions. Additionally, there is no need to trust middlemen to verify and execute smart contracts correctly and quickly. As a result, smart contracts can be cheaper, faster, and more secure than traditional contracts.
Also, smart contracts inherit the transparency and security of the distributed ledger they run on. On a public ledger, all transactions are visible to members of the network. This transparency allows you to verify your transaction and rest assured that the exchange happened correctly. Moreover, the records of your transaction cannot be easily altered or deleted on a distributed ledger, and if they are, this change can be made visible to you. These security and transparency benefits are unique to public ledgers and smart contracts.
Finally, smart contracts make complex transactions easy. While smart contracts can be used for simple transactions, they can also define and complete intricate, multiparty exchanges with precise timelines. Languages like Solidity make it possible to code even the most complex transactions, and once a smart contract has been written, it can be used over and over again. Additionally, multiple smart contracts can be used in tandem to execute even more elaborate exchanges.