Booleans in Solidity
The first one youāll need to know are simple booleans. They can be true or false!
Video
Code
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;
}
}
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.
Next
Thatās basically all there is to booleans. They work very similar as in other programming languages. Off to Integers and unsigned Integers!
Last updated on