-
Local Variables
- Temporary variables within functions
- Exist only during function execution
- Not stored on the blockchain
-
Storage Variables
- Defined in the contract’s Storage
- Persist between contract executions
- Stored on the blockchain
-
Global Variables
- Provide blockchain context and information
- Accessible anywhere in the contract
- Read-only system variables
Local Variables
Local variables are temporary variables that exist only within their defined scope (a function or code block). Key characteristics:- Stored in memory, not on the blockchain
- Used for intermediate calculations and temporary data
- Available only during function execution
- Help improve code readability by naming values
Storage Variables
Storage variables provide persistent state for your contract on the blockchain. They have these properties:- Persist between contract executions
- Can be read for free (no transaction needed)
- Require a transaction to write to them
- Must be defined in the contract’s Storage struct
Reading is a free operation, with no transaction needed.Writing requires a transaction and costs gas.
Global Variables
Global variables provide access to blockchain context and system information. In Starknet:- Accessed through core library functions
- Available anywhere in the contract
- Provide critical blockchain context (e.g., caller address, block info)