Data types tell the computer what kind of information we want to store. They help keep data organized and safe.
0
0
Data types (uint, int, bool, address, string) in Blockchain / Solidity
Introduction
When you want to store a number that can only be positive, like a token balance.
When you need to store a number that can be positive or negative, like a temperature change.
When you want to store true or false answers, like if a user is verified.
When you need to store a blockchain address to send or receive tokens.
When you want to store text, like a name or message.
Syntax
Blockchain / Solidity
uint number; // unsigned integer (only positive) int number; // signed integer (positive or negative) bool flag; // true or false address addr; // blockchain address string text; // text string
uint means the number cannot be negative.
address stores a blockchain wallet or contract location.
Examples
This stores a positive number 30 in
age.Blockchain / Solidity
uint age = 30;This stores a number that can be negative, here -5 degrees.
Blockchain / Solidity
int temperature = -5;
This stores a true/false value, here true means active.
Blockchain / Solidity
bool isActive = true;This stores a blockchain address in
owner.Blockchain / Solidity
address owner = 0x1234567890abcdef1234567890abcdef12345678;This stores text, here the name "Alice".
Blockchain / Solidity
string name = "Alice";Sample Program
This smart contract shows different data types. It stores a positive number, a negative number, a true/false value, an address, and some text. The owner is set to the person who creates the contract.
Blockchain / Solidity
pragma solidity ^0.8.0; contract DataTypesExample { uint public tokenBalance = 1000; int public temperature = -10; bool public isVerified = false; address public owner; string public greeting = "Hello, Blockchain!"; constructor() { owner = msg.sender; } }
OutputSuccess
Important Notes
Use uint when you know the number will never be negative.
address is special for blockchain wallets and contracts.
string stores text but can use more gas (cost) on blockchain.
Summary
uint stores positive numbers only.
int stores numbers that can be positive or negative.
bool stores true or false values.
address stores blockchain wallet or contract addresses.
string stores text messages.