I understand from this thread that you're refunded up to 10,000 gas when setting a value to 0.

Does this also apply to boolean values? That is, going from true to false?


Yes, it does. To the EVM, setting a bool to false is equivalent to setting a uint to 0 in that it clears a storage slot.

You can try it out with the code below. In this contract, the following transaction costs are:

setBool() = 41705

setUint() = 41474

unsetBool() = 13386

unsetUint() = 13204

pragma solidity ^0.5.10;

contract RefundTest {

    bool public boolGasTest;
    uint256 public uintGasTest;

    function unsetBool() public {
        boolGasTest = false;

    function setBool() public {
        boolGasTest = true;

    function unsetUint() public {
        uintGasTest = 0;

    function setUint() public {
        uintGasTest = 1;

Note: the gas refund takes place at the conclusion of the transaction. Because of this, you may still hit the block gas limit if your transaction costs more than 8 million gas before the refund.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.