In a blockchain, you can put a set of transactions, but you can also store code that resembles the logic and rules of a real contract.
A Smart Contract is a computer program stored in a blockchain that guarantees the fulfillment of an agreement automatically and safely, without the need for third parties. Smart Contract technology is not new, but how it is applied is.
Smart Contracts run exactly as programmed. They are self-executing with specific instructions or clauses written on their code which get executed when certain conditions are met. For example, when two people participate in a Smart Contract that implements a bet, they'll send the money to the Contract with their selected winner choice. The Contract will be responsible for transferring the amount deposited by the two people to the address of the person who has guessed right. The action of sending money is made using the native token of the blockchain where the Contract is deployed.
Any agreement between individuals or corporations may have clauses whose execution is automated with a Smart Contract deployed in a blockchain. In the case of conflicts, the traditional solution is to go to court to demand compliance with the Contract or compensation for the damages caused, which implies time and costs for the parties. The risk of contract execution can be significantly reduced and very efficiently solved with Smart Contracts and Blockchain technology. It is an automated mechanism that guarantees the execution of the Contract quickly, safely, and cheaply when certain agreed conditions are met.
The blockchain provides a single ledger as a source of trust and strips possible complications in communication and workflow because of its precision, transparency, and automated system.
A Smart Contract that runs on a blockchain needs to be immutable and must have the ability to run through multiple nodes without compromising its integrity. As a result of which, the Smart Contract functionality needs to be deterministic, terminable, and isolated. Deterministic means that the contract output will be the same if identical inputs are given. Terminable implies that the Contract must have an exit when specific conditions are met or a time limit is exceeded. Isolation is needed to evade secondary effects on the platform where the Contract is executed. Since any contract may knowingly and unknowingly contain bugs, the Contract must be executed in an isolated sandbox.
There are lots of Smart Contract use cases. We'll review them in a later post. If you need more profound knowledge about blockchain, you can enroll in any blockchain courses.
For an excellent graphic explanation of how Smart contracts work, you can check this infographic from Raise P2P Lending Platform. They also have a crystal clear Beginner's Guide to Smart Contracts.