Search code examples
visual-studioblockchainethereumsolidityremix

Solidity : After passing it to "true", my bool doesn't pass to false... why?


I'm starting learning Solidity. I'm using Visual Studio Code with Remix IDE extension.

I already have a little problem 😅

I wrote this simple contract :

// SPDX-License-Identifier: UNLICENSED

pragma solidity 0.8.12;

contract test2 {

 bool myBool;

 function getBool() public view returns(bool){
    return myBool;
 }

 function setBool(bool _bool) public {
    myBool = _bool;
 }

I compiled it and deploy it in testnet Blockchain.

After using getBool(), i get a false. Nothing to report here...

Then I set the value true to myBool with setBool(). I get a true after using getBool(). Everything is okay here.

But, when i want to set false to myBool with setBool(), I still obtain a true with getBool(). I don't understand how and why?

Thank you for your help. (Sorry for my english if i made some mistakes)


Solution

  • I have not enough reputation to just comment so it will be an anwer. Your code is correct but there are may be some tricky issues.

    1. The first "false" is the default value as bool is "value type". Read the first paragraph from here.
    2. I would reccomend you use remix ide itself (online version for example). I guess different ide extensions can not be fully trusted.
    3. You may merely had not waited for transaction to be confirmed so you read old value.