My Web3 Journey
Tags: solidity, web3, blockchain, smartcontract
Published: 2021-12-08 10:25:03

If you have been active on the internet in recent times you can't miss the buzz about web3 and what it entails. This is my personal guide as I venture into the world of web3 and decentralisation.

I will write this as a series which I will update as I learn more. This will act as a go to resources on web3 matters.

I will be learning 

* **Solidity** : which is used for developing smart contracts for the Ethereum Virtual Machine or blockchain.

* **EtherJs** : Library for connecting and communicating with the smart contract. A bridge like structure that acts as a connector interacting with the smart contract.

* **Hardhat Library** : For configuring a local blockchain node on your development system.

I am already familiar with :
* **React Js** : For creating a front-end application.

## Smart Contract
Smart Contract are codes that runs on a blockchain. A smart contract lives on the blockchain and once deployed to a blockchain, it can no longer be edited, if there are errors. The code on a smart contract is available for everyone to view.

You can view a smart contract code by using the contract address to search for it on [Ether Scan](https://etherscan.io/) 

Smart contract on the Ethereum blockchain is written in solidity.

## Solidity
Solidity is a programming language that has root and inspiration from C++, Python and Javascript. If you are familiar with Javascript then picking up Solidity won't be a problem. 

Solidity is statistically typed and supports inheritance. Solidity requires a compiler to compile the code. 

The best way to get started with Solidity is by using an online editor called 
[Remix Ide](https://remix.ethereum.org/)

You can also install a Visual Studio Plugin called JuanBlanco.solidity. This plugin helps to installs the solidity compiler and also useful for syntax highlighting.  

## Anatomy of a Smart Contract
````solidity
//SPDX-License-Identifier: MIT 
pragma solidity ^0.8.4; //compiler version.

contract Hello {
   string public message = "Hello, welcome to solidity";
}
````
At the top of the file you have to specify the license. It is very important to include this.

Next is a line that starts with pragma solidity 'compiler version' this line means the version of the compiler that will be used to compile the Solidity file.

pragma solidity ^0.8.4; this line means a compiler not greater than 0.8.4. A code statement is terminated in Solidity with a semi-colon (;). This is very important as the code will not compile if you have a missing ; somewhere in your code.

## Gas
When you perform transactions on the Ethereum blockchain you pay for such transaction. Gas is how much a transaction will cost in Ethereum. Storing data on the block chain requires the payment of gas. Gas is paid in a currency called ethers in Ethereum. Another unit of money is a Wei.

````solidity
 1 ether = 1000000000000000000;
//one ether is equal to 18 zero.
````
Minimising the amount of gas paid is an essential skill to have as a top rated Solidity developer.

## Primitive Data Types in Solidity
Some primitive data types in solidity are:
boolean
uint
int
address
string

### Boolean
This is used to represents data that is true or false. If a boolean data type is not assigned the default value is false.

### Uint
The uint data type is used to store unassigned positive numbers. uint has three types which are uint8, uint16 and uint256. Declaring a variable as uint without specifying the type of uint; solidity will save the data as uint256.

### Int
This is used to store both positive and negative numbers. We have int8 and int256.

### Address
The address data type is used to store the location of a smart contract on the blockchain or the address of the person calling or interacting with the smart contract.

````solidity
//SPDX-License-Identifier: MIT 
pragma solidity ^0.8.4; 

contract PrimitiveDataType {
   string public message = "Hello world";
   uint256 public bigNumber = 0;
   address public contractAddress = 0x0000000000000000000000000000000000000000;
//default value
   bool public isCoding; //defaults to false if not assigned

}

````
In the next series of this journey we will discuss variables modifiers and accessibility. See you next time happy coding....