The old way to create a contract
Smart contracts idea is probably older than you think. Smart contracts were first proposed by Nick Szabo, who coined the term in 1994. You can check his original work:
What is a contract
First of all, let’s have a look at the dictionary definition of a contract:
“A written or spoken agreement, especially one concerning employment, sales, or tenancy, that is intended to be enforceable by law.”
A contract is an agreement between two parties that mutually agreed to behave or act as the contract states. The contract usually has to have a specific form (date, conditions, names, signatures) and if any party does not agree with the acting or not acting of the other party then the law have to get engaged to solve the issue.
The issue is that in the real world a paper contract cannot enforce the correct or honest behavior of the participants. There must be a third party that solves all possible issues. Thus there are so-called legally binding contracts. “Legally binding” means that the parties must obey the terms written in the contract and perform their contract duties as stated. Failure to do so may result in legal consequences, such as a damages award.
We are able to avoid middle-man when we want to send a transaction. A distributed network can act as a middle-man and ensure that a transaction sent by Alice to Bob will be processed as expected if all conditions are met. Bitcoin does it quite well.
Why smart contracts
What if we could create a digital contract and use it similarly as a transaction between Alice and Bob? What if Alice and Bob could create a digital contract between each other and a distributed network, as a middle-man, ensures correct execution and enforces both to act honestly? This is exactly what a smart contract can do. Let’s have a look at what Nick Szabo wrote about it in his work:
We also see that to implement a full customer-vendor transaction, we need more than just the digital cash protocol; we need a protocol that guarantees that the product will be delivered if payment is made and vice versa. Current commercial systems use a wide variety of techniques to accomplish this, such as certified mail, face to face exchange, reliance on credit history and collection agencies to extend credit, etc. Smart contracts have the potential to greatly reduce the fraud and enforcement costs of many commercial transactions. Digital cash protocols use several of the rich new building blocks coming out of the fields of cryptography and computer science. Most of these components have not yet been widely exploited to facilitate contractual arrangements, but the potential is vast.
Finally, we can extend the concept of smart contracts to property. Smart property might be created by embedding smart contracts in physical objects. These embedded protocols would automatically give control of the keys for operating the property to the agent who rightfully owns that property, based on the terms of the contract. For example, a car might be rendered inoperable unless the proper challenge-response protocol is completed with its rightful owner, preventing theft. If a loan was taken out to buy that car, and the owner failed to make payments, the smart contract could automatically invoke a lien, which returns control of the car keys to the bank.
As you can see, Nick stated that we need more than just a transaction system to guarantee that the product will be delivered if payment is made.
It works fine with fiat since there is the law. If an online shop does not deliver a product for that you have already paid then you will engage the law. You will call the police or contact the appropriate national authority. You have a signed paper agreement in your hands and it is what the authority needs to process. It can take some time but eventually, you will probably get your money back or the dishonest online shop will be closed.
Bitcoin network is not able to ensure trust for such simple tasks as online shopping or even sending a value to a person you have never met before. You have to build trust between the counter-party if you want to transact with each other. For example, it can work for the relationship employer-employee. Still, if the employer decides not to pay you after you have hardly worked the whole month you will have to again engage the law.
Even if you do it via an escrow account the parties must find a person to whom they both believe. It is still too complicated and trusted.
So if we really want to utilize the whole potential of distributed networks we need to resolve the mentioned payment issues and establish trust between parties. It is what smart contracts can do for us.
How smart contracts work
A paper contract is just an agreement and parties are responsible for execution. For example, if Alice promises Bob to pay him $1000 for 4 Tesla stocks then they are both responsible to hand over the money and stocks. They can do it hand-to-hand if they are close to each other. If not, Alice could pay in advance and Bob will send stocks once he receives the money from Alice. In this case, Alice must trust Bob that he is honest and will send the stocks. Alice is at a disadvantage.
A digital smart contract is responsible also for the execution part of the agreement.
The situation will be much better for Alice and Bob if they utilize a smart contract. First of all, they make an agreement and create a digital form of it. In the smart contract, there will be Bob’s address for the payment and the amount of money Alice must send. There will also be Alice address for the stocks and expected amount. Once the contract is so-called deployed, what is a similar process to signing a paper agreement, the execution part is fully in control of the distributed network that processes the smart contract and nobody is able to change it or stop it. Neither Alice and Bob nor anybody else in the world.
The smart contract is 100% fair and does exactly what is supposed to do. It does not matter the order in which Alice and Bob send promised assets. The smart contract is able to keep digital cash and stocks in a temporary dedicated account. Once the smart contract is able to swap the assets it does it. If one party does not send the asset then after a specified time the contract sends back the asset that is in the temporary account to the former owner. Nobody can cheat and it never happens that one party has both assets and the other none. The smart contract is a trustworthy and reliable middle-man. Notice, that there is no reason to engage the legal authority at any moment. The smart contract is conflict-free meaning that if it is written smartly then it takes into account all possible results and all parties exactly know what happens under given conditions and when. Smart contracts behave deterministically.
What is a smart contract
A smart contract is a computer code that has to be written by a special smart contract programming language. In other words, a smart contract is an automatically executable set of rules that were provided via a computer program.
The code is written off-chain by a programmer and then has to be deployed what is a similar process as sending a transaction. A transaction is also built in a wallet and then sent to the network. Once the contract is deployed it is stored in the blockchain and it is executed by a special piece of software called virtual machine.
Virtual machines run on nodes in the distributed network and execute smart contracts. The execution result is then taken and mutual consensus among nodes must be achieved. This is very similar to what happens with common transactions. You can imagine that as a big global computer that consists of many distributed nodes. So the contract between Alice and Bob is processed on many computers and the consensus must be achieved to have a single version of the truth and/or behavior.
A smart-contract code allows decentralized automation by facilitating, verifying, and enforcing the conditions of an underlying agreement. During the execution of smart contracts, it is verified whether all conditions are met to produce some expected outcome or perform some predefined action.
Smart contracts will be most beneficial in business collaborations where parties can agree on something, build a contract and let it automatically execute. It is useful for any kind of sales, loans, purchases, bet, and more. Smart contracts reduce the risk of fraud or tampering, and as there is no third-party involved, the costs are also reduced.
Cardano smart contracts programming language Plutus
Smart contracts for Cardano will need to be written in Plutus or IELE and is intended to support a higher level of assurance. Plutus is a smart contract language using the Haskell programming language. Haskell is recognized at the academic and developer level for its mix of academic and industry-grade talent with core credentials in computer science. Thus, writing smart contracts will be safer and more reliable than any other smart contract language. Plutus Platform will be a Haskell library and will be an accessible toolbox for developers to create smart contracts and can support code that runs on-chain and off-chain. Due to peer review and high assurance, the code for the Cardano smart contracts is secure, tested, and documented. Ultimately, it is this research-first driven approach used by a professionally credentialed team of academics and cryptography experts that separates Cardano and Cardano smart contracts from others in the space.
You have a look at Plutus and try to write, compile and test a smart contract in online Plutus Playground: https://prod.playground.plutus.iohkdev.io/
Marlowe is a new language for modeling financial instruments as smart contracts on a blockchain. It has been designed for people who are business engineers or subject experts rather than experienced developers. It is a simple domain-specific language (DSL) which comprises a small number of powerful building blocks that can be assembled into expressive financial contracts. It is embedded in the Haskell language, which has its own established ecosystem and testing framework. You do not need programming expertise to use Marlowe and you can explore your Marlowe financial constructions with a browser-based contract editor and simulator.
Marlowe interacts with real-world data and enables the expression of smart contacts. It is aimed at fixed-duration financial products, such as hedging, fixed-term deposits, credit swaps, and crowdfunding. Marlowe is ideal for financial start-ups, analysts, or those in the fin-tech community as well as universities who could use it for testing within their financial courses. With Marlowe, you can write smart contracts for financial instruments that are easy to read, write, and understand without programming experience.
Check Marlowe Playground: https://testnet.iohkdev.io/marlowe/tools/marlowe-playground/
As Charles Hoskinson said in one interview “ One of the biggest problems with Bitcoin, is that it’s blind, deaf and dumb and that was by design.”. Bitcoin was never intended to replicate the current financial systems and be compliant with them. However, we desperately need it to continue building a decentralized world. It will not be easy at all and there is a long way to go in front of us. People must learn new programming languages and blockchain principles to build reliable smart contracts. They have to know that what is deployed once it cannot be changed and stopped. There is no space for human errors. It will take a long time until Alice and Bob use a smart contract for swapping assets. However, we believe that we will see that happen in business soon.