Challenge 4
Gas Optimization & Storage Refunds
GasGas optimization
Challenge
What do you think the gas costs will be when setting this value to a new number and then resetting it to zero?
Starter code
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract GasTest {
uint256 public number;
function setNumber(uint256 _num) public {
number = _num;
}
}Show hint
Storage writes cost gas, but clearing a nonzero storage slot may receive a refund. Compare the transactions.