Value DataTypes Details
- Signed/Unsigned integers - Integer data types store whole numbers, with signed integers storing both positive and negative values and unsigned integers storing non-negative values.
- Booleans - Boolean data type is declared with the bool keyword, and can hold only two possible constant values, true or false.
- Fixed-point numbers - Fixed point numbers represent decimal numbers in Solidity, although they aren’t fully supported by the Ethereum virtual machine yet.
- Addresses - The address type is used to store Ethereum wallet or smart contract addresses, typically around 20 bytes. An address type can be suffixed with the keyword “payable”, which restricts it to store only wallet addresses and use the transfer and send crypto functions.
- Byte arrays - Byte arrays, declared with the keyword “bytes”, is a fixed-size array used to store a predefined number of bytes up to 32, usually declared along with the keyword (bytes1, bytes2).
- Literals - Literals are immutable values such as addresses, rationals and integers, strings, unicode and hexadecimals, which can be stored in a variable.
- Enums - Enums, short for Enumerable, are a user-defined data type, that restrict the value of the variable to a particular set of constants defined within the program.
- Contract & Function Types - Similar to other object oriented languages, contract and function types are used to represent classes and their functions respectively. Contracts contain functions that can modify the contract’s state variables.
Value Datatype and Keywords
| Type | Keyword | Details |
|---|---|---|
| Boolean | bool | true/false |
| Integer | int/uint | Signed and unsigned integers of varying sizes |
| Integer | int8 to int256 | Signed int from 8 bits to 256 bits. int256 is the same as int. |
| Integer | uint8 to uint256 | Unsigned int from 8 bits to 256 bits. uint256 is the same as uint. |
| Fixed Point Numbers | fixed/unfixed | Signed and unsigned fixed point numbers of varying sizes. |
| Addresses | address | The address type is used to store Ethereum wallet or smart contract addresses, typically around 20 bytes |
Reference Datatype
Reference type variables store the location of the data. They don’t share the data directly. With the help of reference type, two different variables can refer to the same location where any change in one variable can affect the other one.
| Type | Details |
|---|---|
| Arrays | An array is a group of variables of the same data type in which the variable has a particular location known as an index. By using the index location, the desired variable can be accessed. The array size can be fixed or dynamic. |
| Strings | Strings are like arrays of characters. When we use them, we might occupy bigger or shorter storage space. |
| Struct | Solidity allows users to create and define their own type in the form of structures. The structure is a group of different types even though it’s not possible to contain a member of its own type. The structure is a reference type variable that can contain both value type and reference type |
| Mapping | Mapping is the most used reference type, that stores the data in a key-value pair where a key can be any value type. It is like a hash table or dictionary as in any other programming language, where data can be retrieved by key. |
Question / Answer
The address type is used to store Ethereum wallet or smart contract addresses
Bibliography/References
- None