From bde9d34832aaf7998aa34267b3dffb6748da7806 Mon Sep 17 00:00:00 2001 From: FinagleLord <72840971+FinagleLord@users.noreply.github.com> Date: Fri, 20 Aug 2021 00:08:48 -0600 Subject: [PATCH] Change booleans to uints "Under the hood of solidity, Booleans (bool) are uint8 which means they use 8 bits of storage. A Boolean can only have two values: True or False. This means that you can store a boolean in only a single bit." So I adjusted "unlocked" to uint256 to save some gas :) --- src/lock.sol | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/lock.sol b/src/lock.sol index 128b11d..bd0572e 100644 --- a/src/lock.sol +++ b/src/lock.sol @@ -2,13 +2,12 @@ pragma solidity ^0.8.6; contract Lock { - bool unlocked = true; + uint unlocked = 1; modifier lock() { require(unlocked, "lock/locked"); - unlocked = false; + unlocked = 0; _; - unlocked = true; + unlocked = 1; } } -