TRÄW🤟
TRÄW🤟

@thatstraw

16 Tweets Dec 10, 2022
Web 3 Solidity - Datatypes in Solidity
🧶 thread ↓
Like in any other programming language, datatypes in Solidity can be classified into two types: value and reference type.
Value types store values: for example, boolean stores true or false, and the datatype of uint stores positive integers.
On the other hand, reference types don't store values, they store a reference to where the actual data is stored. For example, an array is a data type of type reference. An array stores a reference to where the actual array elements are stored.
In this thread, I will be discussing value type datatypes.
Examples of value types in solidity:
• bool - The possible values are constants true and false.
• uint - unassigned integer stores numbers that are greater or equal to zero.
So you can't use negative numbers with unassigned integers. Uint is the same as uint256, and uint256 ranges from 0 to 2**256 - 1.
They're variants of uint with different ranges, i.e uint8 ranges from 0 to 2**8-1, and this goes all the way up to uint256 in steps of 8.
• Uint only supports positive numbers, so no negative numbers, but what if you want to use negative numbers?
Fortunately, solidity has the int that supports both negative and positive numbers.
Int is also the same as int256 and it ranges from -2**255 to 2**255-1.
Like uint, int also has some variations offering different sizes, i.e. int64.
You don't need to remember the sizes of these datatypes. Fortunately, solidity offers a quick way to find the maximum and minimum size of a variable.
Here is an example:
• address - is another value type datatype you will be using often in solidity.
An address holds a 20 byte value (size of an Ethereum address).
• bytes - Bytes are used to store a fixed-sized character set. The length of bytes is from 1 to 32.
•The last data type I will be showing you is the string data type.
A string is used to store the character set of any length.
That is it for this thread. I hope you found it useful. If you need any help, please let me know in the comment section.
I know I didn't cover all the datatypes in solidity, but these are the common ones you will be using more often.
If you found this thread helpful,:
🔁RT the first tweet and help others find this thread
✅Follow me @xtremepentest
For more amazing Solidity content.

Loading suggestions...