0
0
Blockchain / Solidityprogramming~10 mins

Data types (uint, int, bool, address, string) in Blockchain / Solidity - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Data types (uint, int, bool, address, string)
Start
Declare variable
Assign value
Check type
uint?
YesStore unsigned integer
int?
YesStore signed integer
bool?
YesStore true/false
address?
YesStore blockchain address
string?
YesStore text
Use variable
End
This flow shows how a variable is declared, assigned a value, checked for its data type, and then stored accordingly before being used.
Execution Sample
Blockchain / Solidity
uint age = 30;
int temperature = -10;
bool isActive = true;
address user = 0x1234567890abcdef1234567890abcdef12345678;
string name = "Alice";
This code declares variables of different blockchain data types and assigns values to them.
Execution Table
StepVariableValue AssignedType CheckedStored AsNotes
1age30uintunsigned integer30 is positive, fits uint
2temperature-10intsigned integer-10 is negative, fits int
3isActivetrueboolbooleantrue or false value
4user0x1234567890abcdef1234567890abcdef12345678addressblockchain addressHexadecimal address format
5name"Alice"stringtext stringText enclosed in quotes
6----All variables declared and stored correctly
💡 All variables assigned and stored according to their data types.
Variable Tracker
VariableStartAfter AssignmentFinal
ageundefined3030
temperatureundefined-10-10
isActiveundefinedtruetrue
userundefined0x1234567890abcdef1234567890abcdef123456780x1234567890abcdef1234567890abcdef12345678
nameundefined"Alice""Alice"
Key Moments - 3 Insights
Why can't we assign a negative number to a uint variable?
Because uint means unsigned integer, it only stores zero or positive numbers. See step 1 in execution_table where 30 is stored as uint, but negative numbers like -10 go to int type as in step 2.
What is special about the address type compared to string?
Address stores a blockchain address in hexadecimal format, which is different from string that stores general text. Look at step 4 and 5 in execution_table for the difference.
Can bool store values other than true or false?
No, bool only stores true or false values. Step 3 shows bool storing true, any other value would cause an error.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what type is the variable 'temperature' assigned to?
Aint
Buint
Cbool
Dstring
💡 Hint
Check step 2 in execution_table where 'temperature' is assigned -10 and stored as int.
At which step does the variable store a blockchain address?
AStep 1
BStep 3
CStep 4
DStep 5
💡 Hint
Look at step 4 in execution_table where 'user' is assigned an address value.
If we assign false to 'isActive', how would the variable_tracker change?
A"isActive" would show true after assignment
B"isActive" would show false after assignment
C"isActive" would show "false" as a string
D"isActive" would be undefined
💡 Hint
Boolean variables store true or false values, so the variable_tracker would show false after assignment.
Concept Snapshot
Data types in blockchain:
- uint: unsigned integer (0 and up)
- int: signed integer (positive and negative)
- bool: true or false
- address: blockchain address (hex format)
- string: text in quotes
Assign values matching type to avoid errors.
Full Transcript
This lesson shows how blockchain variables are declared and assigned values of different data types: uint for positive numbers, int for negative and positive numbers, bool for true or false, address for blockchain addresses, and string for text. Each step assigns a value and stores it according to its type. Beginners often confuse uint and int because uint cannot hold negative numbers. The address type is special for blockchain addresses, different from strings. Boolean variables only accept true or false. Understanding these types helps avoid errors when writing blockchain code.