A smart contract is simply just code that is executing on the blockchain.
In other words, a smart contract is a self-executing contract in which the conditions of the buyer-seller agreement are encoded into lines of code. Smart contracts allow trustworthy transactions to be done between individuals without the requirement of a centralized authority or legal system.
These smart contracts often go by the "IF..", "THEN.." logic, and they are executed when both conditions are met. By using this code logic, it's making them easy to code and seamless when executing.
These conditions might include transferring payments to the proper parties, providing alerts, or issuing a ticket. When the transaction is completed, the blockchain is updated. This implies that the transaction cannot be modified or removed from the blockchain.
Smart contracts also eliminate the human aspect of an agreement, which is typically the largest point of failure in an agreement.
Benefits of smart contracts
Efficiency - Less friction and faster execution.
Trustworthy and decentralized - Doesn't have a point of failure and it doesn't involve the need for a third-party involvement.
Automated - No one needs to act, and humans do not execute these contracts which makes them error-resistant.
Smart contacts history
An American computer scientist by the name of Nick Szabo proposed smart contracts for the first time in 1994. It's interesting to know that Nick Szabo invented a virtual currency called "Bit Gold" in 1998, ten years before the invention of Bitcoin, hence, Nick Szabo is often thought to be the real Satoshi Nakamoto, the anonymous creator of Bitcoin, but of course, Nick Szabo denied this.
Szabo compared a smart contract to a vending machine to demonstrate his point. People would insert money into the machine and if the amount entered is correct - then the machine will give the products ordered, which is the same "IF..", "THEN.." code logic. He explained that this interaction requires little to no trust between the parties: The vending machine has no option but to provide the items once the money is received. The machine's technological architecture ensures that the contract will be completed as it was intended.