In this track: Write and read Solidity
advanced · 4 MIN READ

Boolean and integer types

Types define representable values and operations, not economic meaning.

LET’S PICTURE IT

A form can require a yes/no answer in one field and a whole number in another.

SEE IT FOR YOURSELF
A valid counter call, step by stepStep 1 / 4
A valid counter call, step by stepFunction requestincrement()No argumentsBefore executionstored count0A local teaching example with a defined starting stateIncoming callCheck function dispatchCheck coded conditionsRules passConditions passContinue executionA failed check can revert insteadCalculation0 + 1Result: 1Storage writecount = 1Persists if call succeedsCalculating a local value and storing it are separate stepsPersistent statecount1Later readGetter reports 1No new incrementState, logs and browser display have different roles

This example begins with count zero and a request to call increment(). No real contract is deployed.

Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.

Booleans express conditions

bool values are true or false. They can control branches or record flags. A variable called active does not enforce a permission unless code actually checks it.

Integer widths define ranges

Unsigned integers represent non-negative values, while signed integers include negative values. Widths come in supported bit sizes, with uint as a shorthand for uint256.

Arithmetic has rules

Modern Solidity normally checks overflow and underflow outside unchecked blocks. Integer division discards the fractional component according to the type’s rules, so precision and rounding remain design choices.

Units need separate specification

A uint256 could mean Wei, a token quantity, a counter or a timestamp. Type correctness alone does not prove a caller supplied the intended unit or range for the application.

Read the example

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

contract LearningExample {
    bool public active = true;
    uint256 public count = 7;

    function setActive(bool next) external {
        active = next;
    }
}

This intentionally open toy setter demonstrates types, not a production authorization policy.

QUICK CHECK · NO PRESSURE

Does uint256 automatically mean Wei?

Your progress stays in this browser.
Keep exploring the original referenceSolidity documentation ↗

Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.