Solidity Steps
  • Learning Solidity
  • Step 1
    • 1: Introduction
    • 2: Data Types
    • 3: Functions
    • 4: Control Structures
    • 5: State Variable
    • 6: Local Variables
    • 7: Global Variables
    • 8: View Keyword
    • 9: Pure Keyword
  • STEP 2
    • 10: Immunable Keyword
    • 11: Events
    • 12: Condition
    • 13: While Loop
    • 14: Do While Loop
    • 15: For Loop
    • 16: Required
    • 17: Assert
    • 18: Revert
    • 19: Modifier
  • STEP 3
    • 20: Constructor
    • 21: Mapping
    • 22: Array
    • 23: Enum
    • 24: Structs
    • 25: Data Location
    • 26: Inheritance
    • 27: The Shadowing Effect
    • 28: Super Keyword
    • 29: Visibility
  • STEP 4
    • 30: Interface
    • 31: Abstract Contract
    • 32: Payable
    • 33: Using type()
    • 34: Sending Ether
    • 35: Receive
    • 36: Fallback
    • 37: Call
    • 38: DelegateCall
    • 39: Calling Other Contracts
  • STEP 5
    • 40: Factory Contract
    • 41: Proxy Contract
    • 42: Create2
    • 43: Try and Catch
    • 44: Solidity Library
    • 45: ABI Encoded
    • 46: ABI Decoded
    • 47: Keccak256
    • 48: Function Signature Hash
  • TIPS
    • Tips: Solidity by "Immunable"
    • Tips: Truffle Tutorial
    • Tips: Microblog Dapp
    • Tips: Reentrancy
    • Tips: Slither Tutorial
    • Tips: Remix Tutorial
    • Tips: Hardhat Tutorial
  • CAREER
    • 💲Cover Letter
    • 💲Resume
  • ABOUT
    • Contact me
Powered by GitBook
On this page
  1. Step 1

7: Global Variables

Global variables are variables that are declared outside of any function, class, or contract. They are available to all functions, classes, and contracts within the same scope. Tips: some times you declare Error like global variable.

Global variables are declared with the global keyword followed by the type of the variable and its name. global keyword censored in solidity

    global uint256 myGlobalVariable;
    
    // OR

    uint256 myGlobalVariable;
    contract Name{
        ...
    }

The value of a global variable is initialized with the constructor, and can be modified by any function, class, or contract within the same scope.

constructor() public {    
    myGlobalVariable = 0;  
}    

    function setMyGlobalVariable(uint256 _value) public {    
        myGlobalVariable = _value;  
}

That's it for the lesson 7! In the next lesson, View Keyword

Previous6: Local VariablesNext8: View Keyword

Last updated 2 years ago