4. Storing data
Smart contracts have a private storage space where different types of data members can be defined and used throughout the contract. These data members persist across transactions and can be changed by one transaction and read by another.
It is important to note that all data members must be defined on the top level of the contract and identified by a unique name. After the contract has been deployed, no new data members can be introduced. The storage system in BigBang consists of three types: constants, variables, and data maps.
Constant values are defined on the top level of the contract and cannot be changed. They are useful for defining the contract owner, error codes, and other static values. Variables, on the other hand, can be changed by future contract calls and have an initial value. Each variable contains exactly one value of a predefined type. Maps are collections of data identified by other data. They are used to relate one value to another, such as relating specific principals to unsigned integers to keep track of scores. Although data members are private, meaning only the current contract can use them, it does not mean that they are hidden. Data members should never be used to store sensitive information like passwords or private keys on the blockchain since anything on the blockchain is inherently public. The chain state allows for effortless extraction of any data member's value.
Last updated