How to build smart contracts in solidity?

Sumita Pathak's photo
Sumita Pathak
·Nov 27, 2022·

3 min read

Coding in web3 is a huge career opportunity right now as there is a lot to build and a lot to improve. dApps are continuously being built to complete the ecosystem. The languages that are widely used in web3 are Javascript, solidity and rust. Solidity is the most beginner-friendly language that can be adopted by anyone .Learning a new language is not the only way to get into web3 . You can also transition from web2 to web3 by using the resources here- Resources you need for practical experience in web3 from experts and recruiters themselves :

Ethereum is a open source network where you can deploy your code to build products. These codes are called smart contracts. Smart contracts can be written to run governance, earn commission and even to rent you Netflix account.

Here are the basic elements of solidity code that you can use to build your own smart contract-


All solidity source code should start with a "version pragma" i.e declaration of the version of the Solidity compiler this code should use. This is to prevent issues with future compiler versions.

pragma solidity >=0.5.0 <0.6.0;

Then declare a contract

contract <Contract name>{
uint <state variable> =<variable_value>;

uint → unsigned integer value that must be non-negative

State variables are permanently stored in contract storage. This means they're written to the Ethereum blockchain

Mathematical operators like modulus, addition, exponential etc. work the same .

Exponential operator → **


Then we have structs which are like classes. They basically are a collection of variable of different types .Structs can be described as a box of variable which can be used as a whole.

e.g. You can use structs to store employee data in an Ethereum block that includes id, name, and salary details as a single entity.

struct <Struct name>{uint id;
   string name;
   uint salary;}

It is just like a data type so declare it within the contract.


There are two types based on size-

a) fixed array- Has a fixed length.

uint [] ;

b) dynamic array- Has variable length.

uint[] ;

struct <struct_name> {
        string <variable_name>;
        uint <variable_name>;

 <struct_name>[] public <array_name>;
//this is a public array  of type struct

Public array →Other contracts will be able to read from public array, but not write to.

Declaration of public array → [] public ;

Syntax to add elements in array→ .push() ;


There are two ways in which you can pass an argument to a Solidity function:

  • By value, which means that the Solidity compiler creates a new copy of the parameter's value and passes it to your function so it doesn’t point to the address of the original parameter. This allows your function to modify the local value without worrying that the value of the initial parameter will get changed.
  • By reference, which means that your function is called with a reference(original address) to the original variable. Thus, if your function changes the value of the variable it receives, the value of the original variable gets changed.
function <function name> (<reference type> memeory <var_name>,
<value type> <var_name>) public{

Types of functions in solidity→

  • Public functions→ In solidity functions are public by default.

  • Private functions→ This means only other functions within our contract will be able to call this function .

End Note

I am continuously learning about web3 and its development. You can expect further posts on this blog as a beginner’s guide to web3, blockchain and their various components like dAO, Defi , cryptocurrency etc. I post my shorter learnings on twittereveryday, so you can follow to learn in snippets daily.

Share this