Solidity for busy developers
Published: 2022-05-04 15:13:59


**This article assumes you have a prior experience in programming ..(if you know how to use variables,functions and classes then you should be good to go).**

After reading this tutorial you should be able to create a simple smart contract of your choice.

According to the official [documentation](https://docs.soliditylang.org/en/v0.8.13) _solidity  is an object-oriented, high-level  programming language for implementing smart contracts_.If you are new to web3 you might be wondering what the fun are  smart contracts??
![What is solidity](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6qadl7og7dtk7dkdzcg3.png)
Smart contracts are simply **programs** stored on a **blockchain** that runs when predetermined conditions are met.Note they must be self executing computer program and should be stored on the blockchain(so no single party/entity can control it).
So let's start coding in solidity 🥳.Wait!! what about IDE setup? the code editor we will be using is an online IDE called [Remix](https://docs.soliditylang.org/en/v0.8.13) but feel free to use any other editor of your choice.

- **Layout of solidity source file**
Solidity file ends in .sol and its required to add at the beginning file.
```
//SPDX-License-Identifier: MIT
```
so the source code can can be made available openly.

<center>**Variables and Data types<br>**</center>
**Variables<br>**
Generally there are three types of variables in solidity
which are global,local,state variables.
- Global variables are variables built into solidity that can be accessed anywhere on the solidity source file. example includes
```
msg.sender, tx.origin , block.timestamp
```
- Local variables are variables that are declared in a function e.g
```
function name()public returns(uint){
        uint age = 24;
        return age; 
}
```
Also note as declared above every statements ends with a semicolon and return types of every function must explicitly declare it return type unless it doesn't return any value.
- State variables are variables that are declared in a [contract](https://docs.soliditylang.org/en/v0.8.13/introduction-to-smart-contracts.html#:~:text=A%20contract%20in%20the%20sense,unsigned%20integer%20of%20256%20bits),contracts are the solidity version of class defined by the contract keyword followed by the name of the contract. 
```
contract Ballot {
}
```
**Data types<br>**
Solidity has numerous data types which are subdivided into two categories _referenced_ types and _value_ types.The _value_ of **value** type is the actual value while the _value_ of **reference** type is a reference to another value just like pionters in C++ and Go.

|Type     |keyword |Description |
| ----------- | ----------- | ----------- |
|Adress      |address       | This is the data type for address (both contract and [EOA])(https://ethereum.stackexchange.com/questions/5828/what-is-an-eoa-account)/smart contract    |
|Boolean   |bool        |Can either be true/false , the default value is false     |
|Unsigned integer      |uint(uint8,uint16...uint256)| Can take only positive integers only.It has different variant ranges from uint8 to uint256 a step count of _8_             |
|integer   |int        |  Can take both negative and positive value       |
|Array      |type[](e.g int[],string[])       | Represent series of values     |
|Struct   |struct{}       | Used for modelling data in solidity(Stripped version of class without inheritance method.).They can contain value and referenced types as field.      |
|String      |   string   |Hold string literal values.it is a referenced type|
|Enum   |  enum Name{val_1,val_2,val_3}       |  A user-defined data type that consists of integral constants    |