Learning Objectives – after this chapter you will be able to:
  • Distinguish value types from reference types.
  • Choose the right integer size and know its range.
  • Use address, address payable, bool and fixed-size bytes.
  • State the default value of every basic type.
Two Families of Data Types
FamilyBehaviourTypes
Value typesThe variable holds the data itself. Assigning or passing it to a function makes a copy.bool, int/uint, address, bytes1…bytes32, enum, fixed-point, function types
Reference typesThe variable refers to where the data is stored, so two variables can point to the same data and a change through one is visible through the other (depending on the data location).arrays, bytes, string, struct, mapping

When a reference type is used inside a function, you must state its data location – storage, memory or calldata (Chapter 4).

Value Data Types
  • Booleans – keyword bool; only two values: true or false. Operators: ! && || == !=.
  • Signed / unsigned integers – int stores negative and positive whole numbers; uint stores only zero and positive numbers. Sizes go from 8 to 256 bits in steps of 8 (uint8, uint16 … uint256). uint is an alias of uint256 and int of int256.
  • Fixed-point numbers – fixed/ufixed exist in the language but are not fully supported: they can be declared but values cannot be assigned to or from them. Decimals are therefore handled with integers (for example amounts in wei).
  • Address – address holds a 20-byte Ethereum address of a user account or contract and has members such as .balance.
  • Address payable – address payable is an address that can also receive Ether through .transfer() and .send(). A plain address is converted with payable(addr). (It is not limited to wallet addresses – a contract address can be payable too.)
  • Fixed-size byte arrays – bytes1 to bytes32 hold exactly 1 to 32 bytes. bytes32 is commonly used for hashes.
  • Enums – user-defined types with a fixed list of named constants (Chapter 11).
  • Contract and function types – a variable can hold a contract type (e.g. Token t) or a function reference.
  • Literals – fixed values written in code: numbers (42, 1e18), strings ("abc"), hex (hex"00ff"), Unicode (unicode"₹") and checksummed address literals.
Value Datatype and Keywords
TypeKeywordRange / DetailsDefault value
Booleanbooltrue / falsefalse
Unsigned integeruint8 … uint2560 to 2n−1 (uint8: 0–255)0
Signed integerint8 … int256−2n−1 to 2n−1−1 (int8: −128 to 127)0
Addressaddress20-byte account or contract address0x000…000 (zero address)
Payable addressaddress payableAddress that can receive Ether via transfer/sendzero address
Fixed bytesbytes1 … bytes32Exactly 1–32 bytesall zero bytes
Fixed pointfixed / ufixedDeclared only; not fully supported–

Tip: type(uint8).max returns 255 and type(int8).min returns −128.

Reference Datatype
TypeDetailsDefault
ArraysAn ordered group of elements of the same type, accessed by an index starting at 0. Size can be fixed (uint[5]) or dynamic (uint[]). (Chapter 10)empty / all zero
bytesA dynamic byte array – efficient for raw binary data of any length.empty
stringDynamic UTF-8 text, similar to bytes but without index access or length. (Chapter 9)""
structA user-defined group of variables of different types (a record). A struct cannot contain a member of its own type directly. (Chapter 13)each member at its default
mappingKey-value storage like a hash table or dictionary; every possible key exists and returns the default value until set. (Chapter 12)default value for every key
Example : Declaring Different Types
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

contract DataTypesDemo {
    // value types
    bool    public isActive   = true;
    uint8   public smallNum   = 255;            // maximum value of uint8
    int256  public temperature = -12;
    address public owner      = msg.sender;    // 20-byte address
    bytes32 public fileHash   = keccak256("Solidity");

    // reference types
    uint[]  public marks;                       // dynamic array
    string  public courseName = "Solidity";
    mapping(address => uint) public balances;   // key => value

    function limits() public pure returns (uint8 maxU8, int8 minI8) {
        return (type(uint8).max, type(int8).min);   // (255, -128)
    }
}
Key Takeaways
  • Value types are copied; reference types need a data location and may be shared.
  • uint = uint256; choose smaller sizes only when you know the range.
  • Every variable has a default value – there is no “undefined” or “null” in Solidity.
Download | Print      E-Notes

The PDF E-Notes are the earlier printable version of this chapter. The notes on this page are the latest, revised version.

Video : Solidity Data Types
Resource File
Question / Answer (15 questions)

Answer : A value-type variable stores the data itself and is copied when assigned or passed to a function (e.g. uint, bool, address). A reference-type variable refers to the location of the data, so it may be shared, and it needs a data location (storage, memory or calldata) inside functions (e.g. arrays, string, struct, mapping).

Answer : The address type stores a 20-byte Ethereum address of a user account or a contract. It is used to identify owners, senders and recipients and provides members such as .balance.

Answer : Both store a 20-byte address, but only address payable has the .transfer() and .send() members for sending Ether to it. A plain address is converted with payable(addr).

Answer : uint8 ranges from 0 to 255; int8 ranges from −128 to 127.

Answer : They are the same type: uint is an alias for uint256, and int is an alias for int256.

Answer : Use type(T).max, for example type(uint8).max returns 255; type(T).min returns the minimum.

Answer : No. fixed and ufixed can be declared but values cannot be assigned to or from them, so decimals are represented with integers, such as amounts in wei.

Answer : bool: false; uint: 0; address: the zero address 0x000…000; string: the empty string "". Solidity has no undefined or null values.

Answer : bytes32 is a fixed-size 32-byte value type, commonly used to store hashes such as the output of keccak256, or short identifiers.

Answer : bytes32 is a fixed-size value type holding exactly 32 bytes. bytes is a dynamically sized reference type that can hold any number of bytes.

Answer : A mapping is a key-value store similar to a hash table or dictionary: mapping(KeyType => ValueType) name;, for example mapping(address => uint) balances;.

Answer : A struct is a user-defined type that groups variables of different types into one record, for example a Student with name, roll number and marks.

Answer : Integer/rational literals (42, 1e18), string literals ("abc"), hexadecimal literals (hex"00ff"), Unicode literals (unicode"₹") and checksummed address literals.

Answer : A struct cannot directly include itself as a field because that would require infinite size. It can, however, contain a dynamic array of its own type or be the value type of a mapping member.

Answer : Its range is small (0–255). Since Solidity 0.8, exceeding it makes the transaction revert with an overflow error, so the type must fit every value the variable may hold.
MCQ Test : Check Your Understanding (5 questions)

Select an option and press Check Answer, or answer all questions and press Submit Test to see your score. Each answer comes with an explanation.

Q1. Which of the following is a REFERENCE type?

Show Answer

Correct Answer : C. string
string is a dynamic reference type; the others are value types.

Q2. An Ethereum address occupies:

Show Answer

Correct Answer : A. 20 bytes
Addresses are 20 bytes (160 bits).

Q3. What is the default value of a bool variable?

Show Answer

Correct Answer : D. false
Booleans default to false; Solidity has no null.

Q4. What is the maximum value of uint8?

Show Answer

Correct Answer : B. 255
2^8 − 1 = 255.

Q5. Which member is available on address payable but not on plain address?

Show Answer

Correct Answer : C. .transfer()
transfer() and send() are only on address payable.

Bibliography/References

The notes, questions and MCQs on this page are original explanations written for this course. The works listed below were consulted and are cited for attribution and further reading. Product names, logos and trademarks belong to their respective owners. Short quotations, where used, are marked and attributed.

  1. Solidity Team. (n.d.). Types (value types, reference types, mappings, operators, conversions). Solidity Documentation. https://docs.soliditylang.org/en/latest/types.html
  2. Solidity Team. (n.d.). Cheatsheet. Solidity Documentation. https://docs.soliditylang.org/en/latest/cheatsheet.html
  3. Modi, R. (2018). Solidity Programming Essentials: A beginner’s guide to build smart contracts for Ethereum and blockchain. Packt Publishing. ISBN 978-1-78883-138-3.
  4. Antonopoulos, A. M., & Wood, G. (2018). Mastering Ethereum: Building Smart Contracts and DApps. O’Reilly Media.