0
0
Blockchain / Solidityprogramming~10 mins

Gas optimization with storage in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a storage variable for an unsigned integer.

Blockchain / Solidity
uint256 [1];
Drag options to blanks, or click blank then click option'
Amemory
Bstorage
Ctemp
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'memory' or 'storage' as variable names.
Leaving the variable name blank.
2fill in blank
medium

Complete the code to declare a fixed-size array in storage.

Blockchain / Solidity
uint256[[1]] numbers;
Drag options to blanks, or click blank then click option'
Alength
B5
Ccount
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable names instead of a number for array size.
Leaving the size blank.
3fill in blank
hard

Fix the error in the function to reduce gas by using a local variable for storage reads.

Blockchain / Solidity
function getSum() public view returns (uint256) {
    uint256 [1] = a + b + c;
    return sum;
}
Drag options to blanks, or click blank then click option'
Asum
Btotal
Cresult
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different variable name than the return statement.
Not using a local variable at all.
4fill in blank
hard

Fill both blanks to optimize storage writes by caching in a local variable.

Blockchain / Solidity
function increment() public {
    uint256 [1] = [2];
    [2] = [1] + 1;
}
Drag options to blanks, or click blank then click option'
Atemp
Bcounter
Ccount
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Writing directly to storage multiple times.
Using the same name for both variables.
5fill in blank
hard

Fill all three blanks to create a mapping and update it efficiently.

Blockchain / Solidity
mapping(address => uint256) public [1];

function updateBalance(address user, uint256 amount) public {
    uint256 [2] = [3][user];
    [3][user] = [2] + amount;
}
Drag options to blanks, or click blank then click option'
Abalances
BcurrentBalance
Cbalance
Dtemp
Attempts:
3 left
💡 Hint
Common Mistakes
Using inconsistent variable names.
Not caching the balance before updating.