The most basic type of smart contract is a multi-signature smart contract. A multisig transaction states that a defined number of people (public keys) must sign a transaction with their private keys before it’s considered valid. Bitcoin was the first blockchain to introduce multisig transactions in 2012.
Let’s consider a real-life scenario in which smart contracts are used. Rachel is at the airport, and her flight is delayed. AXA, an insurance company, provides flight delay insurance utilizing Ethereum smart contracts. This insurance compensates Rachel in such a case. How? The smart contract is linked to the database recording flight status. The smart contract is created based on terms and conditions.
Like the blockchain technology used to power most cryptocurrencies, smart contracts were derived from earlier technologies that weren’t quite complete. In the case of smart contracts, they are derived from earlier electronic instruction execution programs that used if/else statements other conditional logic to automatically produce an outcome based on the information it is presented with.
Although the initial use of blockchain was for cryptocurrency such as Bitcoin, blockchain offers much more than just a record of transactions. In addition to trading cryptocurrencies, some implementations of blockchains offer the idea of smart contracts. In particular, the Ethereum is one such example. Like Bitcoin, Ethereum offers a cryptocurrency known as Ether, but it also turned all the nodes in the network into “Turing complete” computers. What this means is that you can write programs (known as smart contracts) and execute them on all the nodes on the network.
Ethereum implements an execution environment on the blockchain called the Ethereum Virtual Machine (EVM). Every node participating in the network runs the EVM as part of the block verification protocol. They go through the transactions listed in the block they’re verifying and run the code as triggered by the transaction within the EVM. Each and every full node in the network does the same calculations and stores the same values.
To understand how a smart contract is useful, let’s imagine the following scenario. You’re a musician and you want to protect your intellectual property, in this case, your music creations. You want to make sure that the lyrics of your songs are protected and that no one else can plagiarize them (especially before they are released). Because data stored on the blockchain is immutable and time-stamped, it’s a good platform to store the lyrics of your songs as the proof that you’re the original creator of the song. However, blockchain data are inherently public, so storing the lyrics of your creation on the blockchain isn’t practical. A good workaround for this case is to store the hash of the song’s lyrics. That way, you maintain confidentiality of your creation, and at the same time you can prove that the lyrics are written by you if you are able to provide the original lyrics to generate the original hash.
More detail: https://www.codemag.com/Article/1805061/Understanding-Blockchain-A-Beginners-Guide-to-Ethereum-Smart-Contract-Programming
The first question that must have come to your mind is, why do we even need a smart contract?
To understand that, consider that you are buying a property for which you need to request a mortgage loan from your bank. Funds approvals and deposit is a multi-step process that involves many parties and lots of regulatory paperwork.