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ā:
- enter ātrueā into the input field
- hit the āsetMyBoolā button
- see if the variable was updated by clicking on āmyBoolā again
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.