Easy way to understand boolean in solidity

Michael FawoleMichael Fawole
2 min read

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.

6
Subscribe to my newsletter

Read articles from Michael Fawole directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Michael Fawole
Michael Fawole

Michael Fawole is a Blockchain and web application developer with 7+ years of experience and 3+ years plus of experience in blockchain dapp development. He is also delivering training on blockchain ( Solidity, web3 and react js ) and php language. He also helps start-ups and companies to setup blockchain practice and incorporating blockchain into existing project. Techstack (Blockchain): Solidity, web3 js and react js. Techstack (Webapp): Php and Mysql.