DEV Community

Jamiebones
Jamiebones

Posted on • Updated on

My Web3 Journey

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

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

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

//SPDX-License-Identifier: MIT 
pragma solidity ^0.8.4; //compiler version.

contract Hello {
   string public message = "Hello, welcome to solidity";
}
Enter fullscreen mode Exit fullscreen mode


`
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.

`

 1 ether = 1000000000000000000;
//one ether is equal to 18 zero.
Enter fullscreen mode Exit fullscreen mode


`
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.

`

//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

}

Enter fullscreen mode Exit fullscreen mode


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

Top comments (0)