Understanding the data types in Solidity might be somewhat stressful due to its variances from other programming languages.
So, in this post, I will be sharing all you need you to know to get started using data types in Solidity.
There are two data types in Solidity namely Value types and Reference types that differ based on the way they are assigned to a variable and stored in EVM. Assigning a variable to another variable can be done by creating a new copy or just by copying the reference. Value types maintain independent copies of variables and changing the value in one variable does not affect the value in another variable. However, changing values in reference type variables ensures that anybody referring to that variable gets an updated value.
Value Type
A data type is referred to as a value type if it holds the data (value) directly
within the memory owned by it. These types have values stored with
them, instead of elsewhere.
The same is illustrated in the following diagram. In this example, a variable of data type unsigned integer (uint) is declared with 20 as its data(value). The variable has memory space allocated by EVM which is referred to as 0x123 and this location has the value 20 stored. Accessing this variable will provide us with the value 20 directly:

Value types do not take more than 32 bytes of memory in size. Solidity provides the following value types:
- bool: The boolean value that can hold true or false as its value.
- uint: These are unsigned integers that can hold 0 and positive values only
- int: These are signed integers that can hold both negative and positive values.
- address: This represents an address of an account on the Ethereum Blockchain Environment.
- byte: This represents a fixed-sized byte array ( byte1 to bytes32 ).
-
enum: Enumerations can hold predefined constant values.
Predefined constants are assigned consecutively, increasing integer values starting from zero. In the example below, males will have an integer value of 0 while females will have one.
Below is a code representation of the above data types used:
pragma solidity ^0.5.0;
contract ValueDataTypesExample {
/* 'public' is used to tell the Ethereum Virtual machine
to make a variable visible and also make it callable
*/
uint public age = 30;
bool isActive = true;
int public temp = -20;
address public sender = msg.sender;
/* msg.sender represents the caller of a smart contract
where msg is a global variable. This address may look
something like
this'0x931d387731bbbc988b312206c74f77d004d6b84b'
*/
bytes1 aa = 0x65;
enum gender {male, female};
}
Reference Type
Reference types, on the other hand, do not store their values directly within the variables themselves. Instead of the value, they store the address of the location where the value is stored. The variable holds the pointer to another memory location that holds the actual data.
Reference types are types that can take more than 32 bytes of memory in size. Reference types are shown in the diagram below.



Solidity provides the following reference types:
- Arrays: The concept of the array data type in Solidity is somewhat similar to the one in other programming languages with a few exceptions. In Solidity, the arrays can be fixed as well as dynamic.
- Structs: These are custom with user-defined structures.
- String: This is the sequence of characters wrapped in quotes which is the same for most programming languages. But, in Solidity, they are stored in bytes.
- Mapping: This is similar to a hash table or dictionary in other languages storing key-value pairs.
Below is a code representation of the above data types used:
pragma solidity ^0.5.0;
contract ValueDataTypesExample {
/* 'public' is used to tell the Ethereum Virtual machine
to make a variable visible and also make it callable
*/
int[5] age;
// array of int with 5 fixed storage space allocated
byte[] flags;
/* array of bytes with no fixed storage space allocated.
Storage is allocated during the assignment.
*/
struct Task {
uint id;
string content;
bool completed;
}
/* This creates a datatype called Task and can be
assigned as follows: Task(1, "Hello", true);
*/
string public name;
mapping (uint => Task) public tasks;
/* The mapping will have a key of an unsigned integer
datatype and a value of the Task datatype that was
declared by the struct.
tasks[1] = Task(1, "Hello", true);
*/
}
Conclusion
The data types in Solidity are a bit different from that of popular programming languages like JavaScript, Python, and Java.
Also, Solidity is a statically typed programming language that’s the datatype is defined during declaration.
I trust you got value out of this post. Let me know in the comments section below.
Also, follow me on Twitter for more amazing content on Blockchain Technology.
Keep coding. Keep learning. God bless you.