Skip to content

Booleans in Solidity

The first one you'll need to know are simple booleans. They can be true or false!


Add the following code to a new file called "ExampleBoolean.sol"

//SPDX-License-Identifier: MIT

pragma solidity 0.8.14;

contract ExampleBoolean {

    bool public myBool;

    function setMyBool(bool _myBool) public {
        myBool = _myBool;


Quick open in Remix

Test the Smart Contract

When you head over to the Deploy & Run Transaction Plugin, try to get the default value of the boolean, which is "false".

Default Value

All variables in Solidity are initialized with their default value. There is no undefined or null!

Update the boolean to true, and then retrieve the value.


That's basically all there is to booleans. They work very similar as in other programming languages. Off to Integers and unsigned Integers!

Last update: September 4, 2022