Eridian
eridian.xyzx.comGitHub
  • πŸ“–Eridian Docs
  • Ethereum Dev
    • ✏️Ethereum Notes
      • πŸŽ›οΈTechnical Basics
      • πŸͺ§Ethereum Addresses
      • πŸ“šEthereum State Explained
      • β›½Gas Fees Explained
    • πŸ”§Useful Tools
      • ☁️Ethers
      • *️⃣Ethernal
    • πŸ“Solidity Notes
      • ❔Interview Questions
        • 🟒1. Easy - Interview Questions
        • 🟠2. Medium - Interview Questions
        • 🟑3. Hard - Interview Questions
        • πŸ”΄4. Advanced - Interview Questions
      • πŸ’‘Note Ideas
      • ABI
      • abi.encodePacked
      • Abstract Contracts
      • Arrays
      • Casting
      • CEI - Checks, Effects, Interactions
      • Comments (NATSPEC)
      • Constructor
      • Contract Structure & Versions
      • Data - Storage vs Memory
      • Data - Storage Layout
      • Enum
      • Errors (require & revert)
      • Events
      • EVM Opcodes
      • External Contract Interaction
      • πŸ—οΈExternal Dependencies
      • Functions
      • Function Modifiers
      • If / Else / For / While Loops
      • Inheritance
      • Interfaces
      • Keccak256
      • Library
      • Mappings
      • msg.sender
      • Objects & Types
      • OpenZeppelin
      • Payable
      • Public State Variable vs Function
      • Receive & Fallback
      • Security
      • Self Destruct
      • Send ETH (transfer, send, call)
      • Stack Too Deep
      • Structs
      • Style Guide
      • Time Units
      • Try / Catch
      • Typecasting
      • Using Directive
      • Variables, Consts & Immutable
      • Withdraws
    • βš’οΈFoundry Notes
      • πŸ“–Docs & GitHub Pages
      • 🀝Useful Commands
        • πŸ”¨Anvil
        • πŸͺ„Cast
        • πŸ”₯Forge
      • πŸ§ͺTests
        • Cheatcodes
      • πŸ“Useful Scripts
        • Deploy Contract Using Hex
    • πŸ‘ΎDeFi Challenges
      • πŸ‘¨β€πŸš€Ethernaut
        • Ethernaut - Template
        • Level 1 - Fallback ⏺
        • Level 2 - Fallout ⏺
        • Level 3 - Coin Flip ⏺⏺
        • Level 4 - Telephone ⏺
        • Level 5 - Token ⏺⏺
        • Level 6 - Delegation ⏺⏺
        • Level 7 - Force ⏺⏺⏺
        • Level 8 - Vault ⏺⏺
        • Level 9 - King ⏺⏺⏺
        • Level 10 - Re-entrancy ⏺⏺⏺
        • Level 11 - Elevator ⏺⏺
        • Level 12 - Privacy ⏺⏺⏺
        • Level 13 - Gatekeeper 1 ⏺⏺⏺⏺
        • Level 14 - Gatekeeper 2 ⏺⏺⏺
        • Level 15 - Naught Coin ⏺⏺⏺
        • Level 16 - Preservation ⏺⏺⏺⏺
        • Level 17 - Recovery ⏺⏺⏺
        • Level 18 - Magic Number ⏺⏺⏺
        • Level 19 - Alien Codex ⏺⏺⏺⏺
        • Level 20 - Denial ⏺⏺⏺
        • Level 21 - Shop ⏺⏺
        • Level 22 - Dex ⏺⏺
        • Level 23 - Dex Two ⏺⏺
        • Level 24 - Puzzle Wallet ⏺⏺⏺⏺
        • Level 25 - Motorbike ⏺⏺⏺
        • Level 26 - DoubleEntryPoint ⏺⏺
        • Level 27 - Good Samaritan ⏺⏺⏺
        • Level 28 - Gatekeeper 3 ⏺⏺⏺
        • Level 29 - Switch ⏺⏺⏺⏺
        • Level 30 - Higher Order ⏺⏺⏺⏺
        • Level 31 - Stake ⏺⏺⏺
      • πŸ’ΈDamn Vulnerable DeFi
    • πŸ”Auditing
      • πŸ—žοΈExploit Resources
      • πŸ”§Audit Tools
    • πŸ€–MEV
  • Infrastructure Docs
    • πŸ’»Hardware
    • 🐧Linux
      • πŸ“–Linux Glossary
      • ⌨️Linux Commands
      • πŸ’ΎInstallation
      • πŸ—οΈMaintenance
      • πŸ–₯️Ubuntu Desktop
      • πŸ›œZeroTier
      • 🎞️TMUX
      • πŸ”΅Bluetooth
    • ⛓️Ethereum Clients
      • βš™οΈExecution Clients
        • ⛏️Geth
          • πŸ’ΎInstallation
          • ⌨️Useful Commands
          • πŸ—οΈMaintenance
        • 🐻Erigon
          • πŸ’ΎInstallation
          • ⌨️Useful Commands
          • πŸ—οΈMaintenance
        • 🧢Besu
          • πŸ’ΎInstallation
          • ⌨️Useful Commands
          • πŸ—οΈMaintenance
      • 🀝Beacon Clients
        • πŸ’‘Lighthouse
          • πŸ’ΎInstallation
          • ⌨️Useful Commands
          • πŸ—οΈMaintenance
        • πŸͺ…Teku
          • πŸ’ΎInstallation
          • ⌨️Useful Commands
          • πŸ—οΈMaintenance
      • πŸ’ŽValidator Clients
        • πŸ’‘Lighthouse
          • πŸ’ΎInstallation
          • ⌨️Useful Commands
          • πŸ—οΈMaintenance
      • βž•L2 Clients
        • πŸ”΅Base
          • πŸ’ΎInstallation
          • ⌨️Useful Commands
          • πŸ—οΈMaintenance
      • πŸ’°MEV Boost
        • πŸ’ΎInstallation
        • πŸ—οΈMaintenance
    • 🚨Alerting and Monitoring
      • πŸ”₯Prometheus
      • 🌑️HealthChecks.io
      • πŸ“ŸPagerDuty
  • General Dev
    • πŸ’ΎGit Notes
      • Repos
      • Committing changes
      • Branches
      • Merging & Rebasing
      • PRs
Powered by GitBook
On this page
  • Types of Objects
  • Example
Edit on GitHub
  1. Ethereum Dev
  2. Solidity Notes

Objects & Types

Last updated 1 year ago

Types of Objects

Type
Description
  • Unsigned integer (whole number)

  • 256 is the default if nothing is specified

    • But it's good to be specific and use uint256

  • Initializes as default 0 if not assigned a value as that is the null value in Solidity

  • Smallest is unit8 as 8 bits is a byte

  • Positive or negative whole number

  • bytes32 is the max size allowed

  • bytes can have "any size"?

    • But I think that will still limit the actual content to 32 bytes

  • Actually a type of bytes in the background, but only used for text

  • boolean

  • true/false

  • An address!

contract SimpleStorage {
    bool hasFavouriteNumber = true;
    uint256 favouriteNumber = 5;
    string favouriteNumberInText = "Five";
    int256 favouriteInt = -5;
    address myAddress = 0x5E666460E5BB4A8Bb14E805478176c36f3b293AB;
    bytes32 favouriteBytes = "cat";
}

Example

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;

contract Primitives {
    bool public boo = true;

    /*
    uint stands for unsigned integer, meaning non negative integers
    different sizes are available
        uint8   ranges from 0 to 2 ** 8 - 1
        uint16  ranges from 0 to 2 ** 16 - 1
        ...
        uint256 ranges from 0 to 2 ** 256 - 1
    */
    uint8 public u8 = 1;
    uint public u256 = 456;
    uint public u = 123; // uint is an alias for uint256

    /*
    Negative numbers are allowed for int types.
    Like uint, different ranges are available from int8 to int256
    
    int256 ranges from -2 ** 255 to 2 ** 255 - 1
    int128 ranges from -2 ** 127 to 2 ** 127 - 1
    */
    int8 public i8 = -1;
    int public i256 = 456;
    int public i = -123; // int is same as int256

    // minimum and maximum of int
    int public minInt = type(int).min;
    int public maxInt = type(int).max;

    address public addr = 0xCA35b7d915458EF540aDe6068dFe2F44E8fa733c;

    /*
    In Solidity, the data type byte represent a sequence of bytes. 
    Solidity presents two type of bytes types :

     - fixed-sized byte arrays
     - dynamically-sized byte arrays.
     
     The term bytes in Solidity represents a dynamic array of bytes. 
     It’s a shorthand for byte[] .
    */
    bytes1 a = 0xb5; //  [10110101]
    bytes1 b = 0x56; //  [01010110]

    // Default values
    // Unassigned variables have a default value
    bool public defaultBoo; // false
    uint public defaultUint; // 0
    int public defaultInt; // 0
    address public defaultAddr; // 0x0000000000000000000000000000000000000000
}

πŸ“
uint
uint8
uint16
uint32
uint64
uint256
int
bytes
bytes2
bytes3
bytes5
bytes22
bytes32
string
bool
address
https://docs.soliditylang.org/en/v0.8.13/types.html
https://solidity-by-example.org/primitives/