0
0
Blockchain / Solidityprogramming~30 mins

Data types (uint, int, bool, address, string) in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Basic Blockchain Data Types
📖 Scenario: You are creating a simple smart contract to store and display different types of data commonly used in blockchain development.
🎯 Goal: Build a smart contract that declares variables of types uint, int, bool, address, and string, assigns values to them, and then outputs these values.
📋 What You'll Learn
Declare a uint variable named myUint with value 100
Declare an int variable named myInt with value -50
Declare a bool variable named myBool with value true
Declare an address variable named myAddress with value 0x1234567890123456789012345678901234567890
Declare a string variable named myString with value "Hello Blockchain"
Create a function getData that returns all these variables
💡 Why This Matters
🌍 Real World
Smart contracts use these basic data types to store and manage blockchain data like balances, flags, addresses, and messages.
💼 Career
Understanding these data types is essential for blockchain developers to write secure and efficient smart contracts.
Progress0 / 4 steps
1
Declare basic data type variables
Declare a uint variable called myUint and set it to 100. Declare an int variable called myInt and set it to -50 inside a Solidity contract named DataTypesDemo.
Blockchain / Solidity
Need a hint?

Use uint for positive numbers and int for numbers that can be negative.

2
Add bool, address, and string variables
Inside the DataTypesDemo contract, declare a bool variable called myBool set to true, an address variable called myAddress set to 0x1234567890123456789012345678901234567890, and a string variable called myString set to "Hello Blockchain".
Blockchain / Solidity
Need a hint?

Remember to use double quotes for strings and the exact address format for address.

3
Create a function to return all variables
Add a public view function called getData inside DataTypesDemo that returns myUint, myInt, myBool, myAddress, and myString in that order.
Blockchain / Solidity
Need a hint?

Use public view and specify the return types in the function signature.

4
Output the stored data
Write a simple script or test code that calls the getData function and prints the returned values in the order: myUint, myInt, myBool, myAddress, myString. For this step, just write a console.log statement inside a JavaScript test function that logs the returned tuple.
Blockchain / Solidity
Need a hint?

Use console.log and convert numbers to strings if needed before printing.