I am new to solidity. When I read the solidity documentation, it says local variable and state variable. But I can't find the definition of the two terms.
Can anyone explain the meaning of local variable and state variable, and the difference between them.
Best Answer
State Variables
From the solidity docs here,
and can be declared in a contract as follow,
Local variables
Carries the usual meaning, that their context is within a function and cannot be accessed outside. Usually these are the variables that we create temporarily to hold values in calculating or processing something. Local variables (of struct, array or mapping) reference storage as pointed out here, local variable will act as an alias for pre-existing one in the storage. Check the example quoted below to understand what happens.
Defaults for the storage location
Here are defaults for the storage location depending on which type of variable it concerns (source):