Bird
Raised Fist0
Blockchain / Solidityprogramming~10 mins

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

Choose your learning style10 modes available
Concept Flow - Data types (uint, int, bool, address, string)
Start
↓
Declare variable
↓
Assign value
↓
Check type
↓
uint?
Yes→Store unsigned integer
↓
int?
Yes→Store signed integer
↓
bool?
Yes→Store true/false
↓
address?
Yes→Store blockchain address
↓
string?
Yes→Store 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.

Practice

(1/5)
1. Which data type should you use in Solidity to store a number that can only be zero or positive?
easy
A. bool
B. uint
C. int
D. address

Solution

  1. Step 1: Understand the difference between uint and int

    uint stands for unsigned integer, meaning it can only hold zero or positive numbers. int can hold both positive and negative numbers.
  2. Step 2: Identify the correct type for only zero or positive numbers

    Since the question asks for numbers that are zero or positive only, uint is the correct choice.
  3. Final Answer:

    uint -> Option B
  4. Quick Check:

    Positive numbers = uint [OK]
Hint: Use uint for non-negative numbers only [OK]
Common Mistakes:
  • Choosing int for positive-only numbers
  • Confusing bool with numeric types
  • Using address for numbers
2. Which of the following is the correct way to declare a boolean variable named isActive in Solidity?
easy
A. bool isActive = 0;
B. bool isActive = 1;
C. bool isActive = "true";
D. bool isActive = true;

Solution

  1. Step 1: Recall the correct boolean values in Solidity

    Boolean variables can only be assigned true or false, not numbers or strings.
  2. Step 2: Check each option for correct boolean assignment

    bool isActive = true; assigns true correctly. Options B and D use numbers, and C uses a string, which are invalid for bool.
  3. Final Answer:

    bool isActive = true; -> Option D
  4. Quick Check:

    Boolean = true or false [OK]
Hint: Assign true or false to bool variables [OK]
Common Mistakes:
  • Using 1 or 0 instead of true/false
  • Assigning strings like "true"
  • Missing semicolon at the end
3. What will be the output of this Solidity code snippet?
int x = -5;
uint y = 10;
bool flag = (x < 0);
string memory text = "Hello";
address addr = 0x1234567890123456789012345678901234567890;

// Output values
x
flag
text
addr
medium
A. Compilation error due to address format
B. 5, false, Hello, 0x1234567890123456789012345678901234567890
C. -5, true, Hello, 0x1234567890123456789012345678901234567890
D. -5, false, "Hello", 0x0

Solution

  1. Step 1: Analyze each variable's value

    x is -5 (signed int), flag is true because x < 0, text is "Hello", and addr is a valid address.
  2. Step 2: Confirm output matches variable values

    -5, true, Hello, 0x1234567890123456789012345678901234567890 correctly lists all values as expected. 5, false, Hello, 0x1234567890123456789012345678901234567890 incorrectly changes x and flag. -5, false, "Hello", 0x0 has wrong flag and addr. Compilation error due to address format is wrong because the address format is valid.
  3. Final Answer:

    -5, true, Hello, 0x1234567890123456789012345678901234567890 -> Option C
  4. Quick Check:

    Variable values printed as is [OK]
Hint: Check variable types and values carefully [OK]
Common Mistakes:
  • Assuming uint can hold negative values
  • Confusing string quotes in output
  • Thinking address format is invalid
4. Identify the error in this Solidity variable declaration:
address myAddress = "0xAbC1234567890";
medium
A. Address must be assigned without quotes
B. Address must be declared as string
C. Address cannot start with 0x
D. Address must be declared as bool

Solution

  1. Step 1: Understand address assignment rules

    In Solidity, addresses are assigned as hexadecimal literals without quotes, not as strings.
  2. Step 2: Identify the error in the code

    The code uses quotes around the address, making it a string, which is invalid for address type.
  3. Final Answer:

    Address must be assigned without quotes -> Option A
  4. Quick Check:

    Address literals have no quotes [OK]
Hint: Assign addresses without quotes to avoid errors [OK]
Common Mistakes:
  • Using quotes around addresses
  • Declaring address as string
  • Removing 0x prefix from address
5. You want to store user information in a Solidity contract with these fields: user ID (positive number), username (text), active status (true/false), and wallet address. Which data types should you use for these fields?
hard
A. uint for user ID, string for username, bool for active status, address for wallet
B. int for user ID, string for username, uint for active status, address for wallet
C. uint for user ID, address for username, bool for active status, string for wallet
D. string for user ID, string for username, bool for active status, address for wallet

Solution

  1. Step 1: Match each field to the correct data type

    User ID is a positive number, so uint fits. Username is text, so string. Active status is true/false, so bool. Wallet address is a blockchain address, so address.
  2. Step 2: Verify options against these matches

    uint for user ID, string for username, bool for active status, address for wallet matches all fields correctly. Other options mix types incorrectly, like using int for user ID or swapping string and address.
  3. Final Answer:

    uint for user ID, string for username, bool for active status, address for wallet -> Option A
  4. Quick Check:

    Match field types carefully [OK]
Hint: Match data types to field meaning exactly [OK]
Common Mistakes:
  • Using int for positive-only IDs
  • Confusing string and address
  • Using uint for boolean values
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard