Variables

Learn about variables in Solidity.

In Solidity, there are three different types of variables:

  • State variables: These are kept in a contract storage facility permanently.

  • Local variables: These retain their values while a function is running.

  • Global variables: These are used to access information about the blockchain.

The state or local variable type must be declared because Solidity is a statically typed language: based on the variable type, every defined variable has a default value.

Guidelines for variable naming

  • Avoid using reserved keywords: Variable names shouldn’t contain any reserved keywords. For example, we can’t use keywords like contract or function as variable names.

  • Start with a letter or underscore: Variable names must begin with a letter or an underscore (_ ...