Solidity for Beginners - Day 1
Tags: web3, blockchain, codenewbie
Published: 2022-10-29 07:05:14

Solidity is a programming language, yes everyone knows it(not everyone though).

But what is it for? It is actually for writing smart contracts on the Ethereum Blockchain.

Since you are here for Day 1. Let's start from the very beginning.

## What is Blockchain?
If we break down the word `Blockchain`, it is `block` and `chain`.
It is basically a chain of blocks where each block is a Computer System that holds data. 

<img src="https://media.giphy.com/media/Xtg9ygGsjvouF7vZ1w/giphy.gif"/>

If you don't understand blockchain, check out this article by [IBM](https://www.ibm.com/in-en/topics/what-is-blockchain) about Blockchains.

Now that we know about blockchains, there are 2 most commonly known blockchains - Bitcoin and Ethereum.

As developers, we develop our software on the Ethereum network.
And we do this using Solidity.

## Solidity basics
As mentioned earlier, Solidity is just another programming language. But what are its features?
Well according to the official Solidity documentation : 

> Solidity is an object-oriented, high-level language for implementing smart contracts. It is a curly-bracket language designed to target the Ethereum Virtual Machine (EVM). It is influenced by C++, Python and JavaScript.

In short, it is like other languages. So, it is easy to learn.

### Now, let's see some important features of Solidity as a language :
 
✅ Specifying the license(optional but required in editors) and the version of solidity you are writing in
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
```

✅ Class based structure where class keyword is replaced by `contract`
```solidity
contract Counter {
    //code goes here...
}
```

✅ Statically typed language with signed and unsigned values
✅ Access modifiers : `public, internal,external and private`
✅ Contracts are used as objects that can be created and modified


Now, that we know the basics, let's write a simple Hello World program as always.
<img src="https://media.giphy.com/media/1n67EigjECnOUc6rhS/giphy.gif"/>

## Counter Program in Solidity
The first and foremost step is to know the version. 
I have been using `Solidity 0.8`.
Also, we will use the MIT license.

We will be using the [Remix IDE](http://remix.ethereum.org) to write our Smart Contracts.

Now the next step is to create our first class with a default value.
We will call the file : `Counter.sol`
```Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract Counter {
    //code goes here...
    uint public count=0;

    function incrementCount() public {
        count = count + 1;
    }
}
```

You can notice that I have used the `uint` or unsigned integer data type as counter cannot be negative. 
Also, it has been set to public as we will be needing to view the value of the counter to use it.

Next is the function increment count. As known by the name, it is a simple function that increases the value of the counter variable.

If you compile this in the remix browser and deploy on the Ethereum Virtual Machine, you can view the value and increment the counter.

Kudos! You have written your first smart contract.

Follow for more upcoming articles on Solidity.