# Smart contracts

Ethereum applications rely on smart contracts as their foundational element. Smart contracts are computer programs that are stored on a blockchain.

`Nick Szabo` first introduced the concept of [smart contracts](https://www.fon.hum.uva.nl/rob/Courses/InformationInSpeech/CDROM/Literature/LOTwinterschool2006/szabo.best.vwh.net/smart.contracts.html) in `1994`, envisioning a [digital marketplace](https://www.fon.hum.uva.nl/rob/Courses/InformationInSpeech/CDROM/Literature/LOTwinterschool2006/szabo.best.vwh.net/smart_contracts_2.html) in which parties could carry out transactions and business functions without the need for intermediaries. His idea has been brought to fruition through the use of smart contracts on the Ethereum platform, which allow for the creation of decentralized applications that can facilitate various transactions and business functions without the need for intermediaries.

To grasp the concept of `smart contracts`, it is important to first understand the basics of `traditional contracts`.

## What is a Contract (Traditional contract)? <a href="#what-is-contract-traditional-contract" id="what-is-contract-traditional-contract"></a>

`Traditional contract` is a legally binding `agreement` between two or more parties that outlines the terms and conditions of a particular relationship. It can be verbal or written, as long as it includes certain conditions. The purpose of a contract is to establish a clear understanding between the parties involved and to provide a course of action in the event that the terms of the contract are not met.

**Here is an example:**

* `Bob's` house is for sale and `Alice` wants to buy it.
* A third party is needed to facilitate the sale and establish trust.
* `Alice` must make an advance payment to `Bob` in the presence of the third party after agreeing on a price.
* `Alice` and `Bob` will sign an agreement outlining the terms and conditions of the sale.
* The `third party` will facilitate the transfer of the original property documents, title, rights, and ownership from `Bob` to `Alice`, following all legal procedures and laws.

**Flaws of a Traditional Contract:**

* **Reliance on Intermediaries:** In a traditional contract, the third party (such as a lawyer or real estate agent) plays a crucial role in facilitating the agreement and establishing trust between the two parties. However, there is a risk that the third party may not fulfill their duties or may even disappear, so it is important to choose a reputable intermediary.
* **Expense:** Traditional contracts can be expensive due to the fees associated with hiring a third party to facilitate the agreement.
* **Time Consumption:** The process of completing a traditional contract can take a significant amount of time, as it involves the involvement of multiple parties such as lawyers and bankers.

## Smart Contracts: <a href="#smart-contracts" id="smart-contracts"></a>

`Smart contracts` are digital agreements stored on a `blockchain` that automatically execute when certain predetermined conditions are met. These conditions are written into the contract's programming code such as solidity.

**For example:**

* `Bob` wants to sell his house.
* `Bob` creates a `smart contract` with the terms and conditions for the sale.
* `Alice` is interested in buying the house.
* `Alice` signs the contract using her private key and pays the agreed upon price.
* The `smart contract` is executed on the blockchain.
* The blockchain network verifies various aspects of the contract, such as `Bob's` ownership of the house and `Alice's` ability to pay.
* If all conditions are met, the `smart contract` automatically transfers ownership of the house from `Bob` to `Alice`.
* The need for `third-party intermediaries` such as lawyers and bankers is eliminated.

### Imagine a smart contract as a vending machine: <a href="#imagine-a-smart-contract-as-a-vending-machine" id="imagine-a-smart-contract-as-a-vending-machine"></a>

A smart contract can be thought of as a vending machine in the sense that it is a self-executing contract with the terms of the agreement.

To use a vending machine, you will typically follow these steps:

* Select a `product` from the menu.
* Insert the correct amount of money for the `product`.
* The `vending machine` will verify the `amount` you have inserted.
* If the `amount` is correct, the `vending machine` will dispense the product.

It's important to note that `vending machines` will not dispense a product if the correct steps are not followed, such as if you do not select a `product` or do not insert enough `money`. This is similar to how a `smart contract` works, where specific outputs are guaranteed in return for specific inputs, as long as certain terms and conditions are met.

### Applications of smart contracts: <a href="#applications-of-smart-contracts" id="applications-of-smart-contracts"></a>

Here are some examples of how smart contracts are being used in the real world:

**1. Auto-pay insurance:** companies like [etherisc](https://etherisc.com/) use smart contracts to automate the process of paying insurance claims.

**2. Decentralized arts and collectibles:** platforms like Foundation, OpenSea, and CryptoPunks allow users to invest in and own digital artwork and collectibles using smart contracts.

**3. Decentralized gaming:** in games like [decentraland](https://decentraland.org/) and [Axie Infinity](https://axieinfinity.com/), players can use smart contracts to trade and own digital assets that have real-world value.

**4. Decentralized technology:** smart contracts are being used in a range of decentralized technology applications, such as the [gitcoin Marketplace](https://gitcoin.co/), a platform for open-source development and the integration of cryptoeconomic systems.
