Solidity is a statically typed language, which means every variable declared must have a type of data to store.
Variables declared in a program to store the data. Solidity provides two types of data types.
It allocates memory size based on datatype.
- Value Types
- Reference Types
Solidity Value Types
- Bool It is a boolean, that contains true/false -Integer types
It provides multiple various integer types
Solidity provides multiple types to store signed and unsigned integers.
singed integers types
:
It uses stores positive and negative numbers
unsigned integers types
:
It uses store positive numbers
Int | Uint |
---|---|
Signed and unsigned numbers | Unsigned numbers only |
Contains Positive and negative values | Positive values |
int8 : - 128 to +127 | uint8 range is 0 to 255 |
int8 to int 256 | uint to uint256 |
verticalPosition | Vertical position - ’top’,’ bottom' |
Notes:
The default value is zero for int and unit types Solidity prevents Overflow errors at compile time only
-Fixed Point Numbers
These are used to store floating numbers with decimal values.
It provides signed and unsigned fixed-point numbers with multiple sizes
singed Fixed types
:
It uses stores positive and negative numbers
unsinged Fixed types
:
It uses store positive numbers
-fixed/ufixed: It is an alias fixed128x18/ufixed128x18. -fixedMxN/ufixedMxN:
M
represents several bits, and the value is divisible by 8. 8 to 256.
N
represents the number of decimals
Fixed | Unsigned Fixed Numbers |
---|---|
Signed and unsigned Fixed numbers | Unsigned Fixe numbers only |
Contains Positive and negative values | Positive values |
Type is Fixed | ufixed type |
Fixed is an alias for fixed128x18 | ufixed is an alias for ufixed128x18 |
fixedMxN |
Solidity Address Type
the address is a type in the solidity that stores blockchain address memory location.
It contains a 20-byte value.
The address contains a properties balance
and transfer
solidity Fixed-size byte array types
It provides multiple byte types - bytes1
, bytes2
… bytes32
.
Another type, bytes
is an alias for bytes1
.