State Variables
Defining State Variables in Rubidity
Overview
State variables are data elements that store the contract's state. In Rubidity, you can define state variables, specify their types, and set visibility options (public
, private
, or internal
) along with additional flags like immutable
and constant
.
Basic Syntax
The basic syntax to define a state variable is as follows:
type
: The type of the variable (uint256
,string
, etc.)visibility
: Visibility of the variable (public
,private
, orinternal
)variable_name
: The name of the state variableflags
: Additional flags like:immutable
or:constant
Examples
Declare a public string variable named name
:
Declare a public unsigned integer named totalSupply
:
Advanced Types
For complex types like mappings and arrays, special syntax is used:
Mappings
Arrays
Automatically Generated Getters
Much like Solidity, for every public state variable, Rubidity automatically generates a getter function.
Accessing State Variables in Contract Logic
In your contract logic, you can access state variables using the s
object:
Flags (Not Yet Implemented)
:immutable
: The variable can only be set once, typically in the constructor.:constant
: The variable's value is set at compile time and cannot be changed.
Last updated