Skip to content

Boolean Types in Solidity

Boolean Types can be true or false. Let's define a simple Smart Contract to play around:

Boolean Smart Contract Example

Create a new Smart Contract in Remix, name it BooleanExample.sol and add the following content:

// SPDX-License-Identifier: GPL-3.0

pragma solidity ^0.8.1;

contract BooleanExample {
    bool public myBool;

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

}

Deploy the Smart Contract

Head over to "Run & Deploy Transactions" Plugin and deploy this Smart Contract.

When you click on "myBool" you will see that the variable is initialized with its default value, which is "false".

Now let's update the variable to "true":

  1. enter "true" into the input field
  2. hit the "setMyBool" button
  3. see if the variable was updated by clicking on "myBool" again

Boolean Operators

With boolean types you have the standard operators at your disposal. Operators: ! (logical negation), && (logical conjunction, "and"), || (logical disjunction, "or"), == (equality), != (inequality).

We will use this in the upcoming projects.

Now you know two very basic types, and we could do already a lot with it, but before we head into our first project, let's see some more peculiarities which you only have in Solidity.


Last update: April 17, 2021