Easy way to understand boolean in solidity

Boolean datatype in solidity

Hello friends, Today I want to explain what we called boolean in solidity. If you have been looking for materials that breaks down the bool data type in solidity and you did not see one, this article is the answer to your search on boolean, so search no more.

What is boolean

I will be giving you a definition that will allow you to grab it easily. Boolean is a datatype in solidity just as we have uint(for numbers), string(for alphanumeric).

Boolean accept either true or false.

Below is how to declare boolean datatype in solidity.

pragma solidity ^0.5.0;

contract Michael{

bool public paused;

}

Let explain the above code.

The variable name is pause, and I set the visibility to public while the data type is bool.

Pause Function

Let us create a function that when it is called, it will set the status of paused to true.

By default, the status of bool data type is false, do not forget.

function Pause(bool x) public {

}

We have created function named Pause and it takes in an input from the frontend whose data type is bool. Remember to set the visibility to public

Next step is to save the input into the state variable by equating paused to the input.

function Pause(bool x){
     paused = x;
}

See the full code below.

pragma solidity ^0.5.0;

contract Michael{

bool public paused;

function Pause(bool x)public {
    paused = x;
}

}

Congratulations, that's concerning bool data type in solidity. In my next article, I will show you how to stop a function from working by using the bool data type.