Day 2: Solidity Fundamental Concepts

Day 2: Solidity Fundamental Concepts

·

2 min read

Solidity is a High-level object-oriented programming language used to implement and develop smart contracts for the Ethereum Blockchain and EVM Based Chains. It is a statistically typed language, variable type has to be specified at compile time.

A smart Contract is simply a program that is stored on the blockchain, which is immutable upon deploying on the blockchain.

Life Cycle of a Solidity Program

Solidity has a Sol C Compiler that takes in the SOlidity program and converts it into 2 parts ABI and ByteCode.

  1. ABI - Application Binary Interface, helps in the interaction between smart contract and frontend. All the information related to smart contracts is stored here.

  2. ByteCode - The Code that is actually stored on the Blockchain, All the Operations and and information related to the instructions on the Smart contract are stored here.

Variables in Solidity

State Variable - A Variable that is stored on the Blockchain Permanently and is present at the contract level.

Local Variable - A Variable that is local to a block or a specific function and is not stored on the blockchain

Functions in Solidity

Functions are a price of code that helps reduce code repetitiveness and increases the modularity of the smart contract.

function fn_name( ) visibility var_usage returns( ){ }, is the syntax of writing a function in solidity.

Visibility Modifications

  • public - Accessible to the outside world, Within the contract, Dereived contract and Other contracts

  • private - Accessible only within the contract

  • internal - Accessible only within the contract and derived contract

  • external - Accessible everywhere except Within the contract as its external to the contract.

Variable Usage

  • view - Used if state variable is only read and not overwritten

  • pure - Used if state variable is neither read or written.

  • neither pure nor view - Used is State variable is overwritten

Constructor

A Special Function that is called by the Solidity Compiler, only one time during the deployment of the contract, Can be used to initialise some values at the start of the contract.

Modifier

Used to reduce the repetitiveness of code, Used inside a function to reduce repetitiveness.

modifier modifier_name(){
    //Repeated Code Here
    _;
}

function fn_name() public modifier_name(){
    //Usage of modifier is done in this way
}