Solidity-Variables

Solidity-Variables

1. Pragma The first line is a pragma directive which tells that the source code is written for the Solidity version eg.

pragma solidity >= 0.5.0 < 0.9.0;

2. Contract A Solidity contract is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereumblockchain. eg.

 Contract State {
  }

3. State variables There are 3 ways to assign value to a state variable

  1. state variable: get stored directly on the blockchain
    uint public age=10;
    
  2. Using Constructor: A constructor code is executed once when a contract is created and it is used to initialize the contract state.
    constructor() public
    {    
        age=10;
    }
    
  3. Using Setter Function: A function is a group of reusable codes that can be called anywhere in your program.
    function setAge() public 
    { 
        age=10;
    }
    

    Follow me Here for more updates:

    Twitter Github