Skip to Content
Courses

Boolean Types in Solidity

Boolean Types can be true or false.

View the Full Course Now 

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; } }

ethereum-blockchain-developer-image

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ā€.

ethereum-blockchain-developer-image

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

ethereum-blockchain-developer-image

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 updated on