DEV Community

eluconsmidar
eluconsmidar

Posted on

Variables in Solidity

There are 3 types of variables in Solidity

  • local

    • declare inside a function
    • not stored on the blockchain
  • state

    • declared outside a function
    • stored on the blockchain
  • global (provides information about the blockchain)

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract Variables {
     // State variables are stored on the blockchain.
     string public text = "Hello";
     uint256 public num = 123;

     function doSomething() public { 
          // Local variables are not saved to the blockchain.
          uint256 i = 456;

          // Here are some global variables
          uint256 timestamp = block.timestamp; // current block timestamp
          address sender = msg.sender; // address of the caller
     }
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay