Solidity Steps
  • Learning Solidity
  • Step 1
    • 1: Introduction
    • 2: Data Types
    • 3: Functions
    • 4: Control Structures
    • 5: State Variable
    • 6: Local Variables
    • 7: Global Variables
    • 8: View Keyword
    • 9: Pure Keyword
  • STEP 2
    • 10: Immunable Keyword
    • 11: Events
    • 12: Condition
    • 13: While Loop
    • 14: Do While Loop
    • 15: For Loop
    • 16: Required
    • 17: Assert
    • 18: Revert
    • 19: Modifier
  • STEP 3
    • 20: Constructor
    • 21: Mapping
    • 22: Array
    • 23: Enum
    • 24: Structs
    • 25: Data Location
    • 26: Inheritance
    • 27: The Shadowing Effect
    • 28: Super Keyword
    • 29: Visibility
  • STEP 4
    • 30: Interface
    • 31: Abstract Contract
    • 32: Payable
    • 33: Using type()
    • 34: Sending Ether
    • 35: Receive
    • 36: Fallback
    • 37: Call
    • 38: DelegateCall
    • 39: Calling Other Contracts
  • STEP 5
    • 40: Factory Contract
    • 41: Proxy Contract
    • 42: Create2
    • 43: Try and Catch
    • 44: Solidity Library
    • 45: ABI Encoded
    • 46: ABI Decoded
    • 47: Keccak256
    • 48: Function Signature Hash
  • TIPS
    • Tips: Solidity by "Immunable"
    • Tips: Truffle Tutorial
    • Tips: Microblog Dapp
    • Tips: Reentrancy
    • Tips: Slither Tutorial
    • Tips: Remix Tutorial
    • Tips: Hardhat Tutorial
  • CAREER
    • 💲Cover Letter
    • 💲Resume
  • ABOUT
    • Contact me
Powered by GitBook
On this page
  • Boolean
  • Integer
  • Address
  • Bytes
  • String
  • Arrays
  • Structs
  • Enumerations
  1. Step 1

2: Data Types

In Solidity, like in many programming languages, variables have a data type that determines the kind of value that can be stored in the variable. Solidity supports a variety of data types, including:

  • Boolean: bool

  • Integer: int and uint of various sizes

  • Address: address

  • Bytes: bytes and byte

  • String: string

  • Arrays: array

  • Structs: struct

  • Enumerations: enum Let's take a closer look at each of these data types.

Boolean

The bool type in Solidity can have one of two values: true or false. It is used to represent conditions that can be either true or false. Here's an example:

bool isReady = true;

Integer

The int and uint types in Solidity are used to represent signed and unsigned integers, respectively. The size of the integer can vary depending on the number of bits used to represent it. Here are some examples:

int8 myInt8 = -10; 
uint256 myUint256 = 1000;

Address

The address type in Solidity is used to represent Ethereum addresses. An Ethereum address is a 20-byte value that represents an account on the Ethereum blockchain. Here's an example:

address myAddress = 0x1234567890123456789012345678901234567890;

Bytes

The bytes type in Solidity is used to represent a dynamic array of bytes. The byte type is used to represent a single byte. Here are some examples:

bytes memory myBytes = new bytes(10); 
byte myByte = 0x12;

String

The string type in Solidity is used to represent a dynamic array of characters. Here's an example:

string memory myString = "Hello, World!";

Arrays

Solidity supports both fixed-size and dynamic arrays. Here's an example of a fixed-size array:

uint256[3] myArray = [1, 2, 3];

And here's an example of a dynamic array:

uint256[] myDynamicArray;

Structs

A struct is a custom data type that allows you to define a collection of variables with different data types. Here's an example:

struct Person { 
    string name; 
    uint256 age; 
} 
Person myPerson = Person("Alice", 25);

Enumerations

An enumeration is a custom data type that allows you to define a set of named values. Here's an example:

enum Color {
    Red, 
    Green, 
    Blue
} 
Color myColor = Color.Red;

That's it for the second lesson! In the next lesson, we'll cover functions in Solidity.

Previous1: IntroductionNext3: Functions

Last updated 1 year ago