Introduction to SOLIDITY !
Tags: solidity, ethereum, development
Published: 2023-01-19 17:33:33

**Solidity** is a programming language that is specifically designed for writing smart contracts and creating decentralized applications (DApps). It is a very powerful language, and its popularity has grown exponentially, similar to that of Python.

## A little Background 

- Solidity was developed by the Ethereum team, led by _Gavin Wood_ and _Christian Reitwiessner_, as a way to program contracts on the Ethereum blockchain.
- The first version of Solidity, version 0.1.0, was released in August 2014, and it has undergone multiple updates and improvements since then.The latest version is ^0.8.0 dec 20 2021
		

## Overview:
Solidity is an object orientd , high level language for immplementing smart contract(DApps). smart contracts are programs which govern the behaviour of accounts within the ethereum state

now what are **smart contracts ?**
A smart contract is a piece of code that is deployed on the Ethereum blockchain and governs the behavior of Ethereum accounts within it. It is a self-executing contract with the terms of the agreement written directly into lines of code. 

The code and the agreements contained therein exist over the Ethereum network and exist as long as the whole network exists.

> In layman terms - A smart contract is a computer program that automatically executes the terms of a contract when certain conditions are met. It is called a "smart" contract because it can self-execute and self-enforce the terms of the agreement, without the need for intermediaries. Think of it as a set of instructions for a computer to follow, that will automatically execute an agreement between two parties, once certain conditions are met.
		
An **_example _**of how a _smart contract_ could be used to govern the relationship between a shopkeeper and a delivery person using an IoT device is as follows:

- A shopkeeper wants to purchase fresh vegetables from a farmer, and the farmer wants to ensure that the vegetables are delivered in good condition, so they agree to use a smart contract to govern the transaction. The shopkeeper hires a delivery person to transport the vegetables from the farm to the store, and the delivery person is given an IoT device that can monitor the temperature inside the truck.

The smart contract is programmed with the following rules:

-The delivery person must maintain the temperature inside the truck below 20 degrees Celsius at all times during the delivery.
-If the temperature inside the truck exceeds 20 degrees Celsius, the smart contract will automatically cancel the payment to the delivery person.
-If the temperature is below 20 degrees Celsius when the delivery is complete, the smart contract will automatically release payment to the delivery person.

This way, the shopkeeper and the delivery person can trust that the vegetables will be delivered in good condition, without the need for intermediaries like third-party inspectors or lawyers. Also, the farmer can be sure that his vegetables will be delivered safely and in perfect condition, as the smart contract ensures that the temperature inside the truck is maintained below 20 degree celsius. 

Overall, this example illustrates how a smart contract can be used to automate and streamline a business process by removing the need for trust between parties and ensuring that the terms of the agreement are executed transparently and automatically.

It is influenced by several other programming languages, including C++, Python, and JavaScript.The syntax of Solidity is similar to that of C++, which makes it easy for developers with C++ experience to learn and use. Additionally, it has many features from Python, such as support for inheritance and complex user-defined types, making it a powerful language for building complex contracts and DApps.

In addition to its syntax, Solidity is also designed to target the EVM, which is the runtime environment for smart contracts on the Ethereum blockchain. This means that Solidity code can be easily compiled to EVM bytecode, which can then be deployed to the Ethereum blockchain and executed by the EVM. This makes it a natural choice for developers looking to build decentralized applications on the Ethereum network.

Overall, Solidity is a language that combines the best features of C++, Python, and JavaScript and is optimized for building smart contracts and decentralized applications on the Ethereum blockchain.	
		
The language Solidity is statically typed, which means that the data type of a variable must be explicitly defined before it can be used in the code. This helps to prevent errors and makes the code more readable and maintainable. For example, if you want to create a variable that will hold an integer value, you 
would define it as "int" or "uint" (unsigned integer) rather than as a general "variable".In addition to being statically typed, Solidity also supports inheritance, libraries and complex user-defined data types such as structs and enums. Inheritance allows the creation of a new contract that inherits the properties and methods of an existing contract, which makes it possible to reuse code and reduces the overall complexity of the code.Libraries are a way to package and reuse code across multiple contracts. This can be useful for functionality that is common across multiple contracts, such as mathematical operations or data storage.

Structs, Enums are complex user-defined data types that allow developers to define custom data structures and enumerated types. 

- Structs, for example, allow developers to create custom data types that can hold multiple variables of different types.
- Enums, on the other hand, allow developers to define a set of named values, which can be used to represent certain states or options in the code.

Overall, the support for inheritance, libraries, and complex user-defined data types makes Solidity a powerful and flexible language for building smart contracts and decentralized applications.


ex: With solidity you can create contracts for uses such as voting, crowd funding, blind auctions and multi-sig wallets we will learn about all these as we move forward.
		
One of the main purposes of a smart contract is to remove the dependence on trust between parties, thus providing a secure and transparent way to execute agreements. One example of how smart contracts can be used to accomplish this is through crowdfunding. Crowdfunding is a process where a large number of people contribute small amounts of money to fund a project, product, or idea. With traditional crowdfunding, the organizer of the campaign must rely on the trust of the contributors to handle and use the funds appropriately. But with smart contracts, the process can be automated and made trustless. A smart contract can be created for a crowdfunding campaign, which will hold the funds in escrow until the fundraising goal is reached. The smart contract can be programmed with a set of rules that dictate how the funds will be released, for example, only after the fundraising goal has been reached or only after certain milestones have been achieved. This way, the contributors can be sure that their funds will be used for the intended purpose, and the organizer of the campaign can be sure that they will receive the funds they need to complete their project. Additionally, smart contracts can also be used to create a transparent record of the fundraising campaign, including how much money has been raised, who has contributed, and how the funds have been used. This transparency helps to build trust between the contributors and the organizer, and also can help to increase the success rate of the fundraising campaign.

Overall, smart contracts can be used to automate and streamline the crowdfunding process by removing the need for trust between the contributors and the organizer, providing a secure and transparent way to execute agreements, and ensuring that the funds are used for their intended purpose.