0
0
Blockchain / Solidityprogramming~10 mins

Storage vs memory usage in Blockchain / Solidity - Interactive 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 in Solidity.

Blockchain / Solidity
uint256 public [1];
Drag options to blanks, or click blank then click option'
AstoredValue
BmemoryValue
CtempValue
DlocalValue
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a variable name that implies temporary or memory usage.
Confusing storage with memory keyword.
2fill in blank
medium

Complete the function to declare a memory array parameter in Solidity.

Blockchain / Solidity
function processData(uint256[] [1] data) public {}
Drag options to blanks, or click blank then click option'
Apersistent
Bmemory
Ccalldata
Dstorage
Attempts:
3 left
💡 Hint
Common Mistakes
Using storage for function parameters which causes errors.
Confusing calldata with memory.
3fill in blank
hard

Fix the error in the function by choosing the correct data location for the string parameter.

Blockchain / Solidity
function setName(string [1] name) public {}
Drag options to blanks, or click blank then click option'
Astorage
Bpersistent
Cmemory
Dcalldata
Attempts:
3 left
💡 Hint
Common Mistakes
Using memory unnecessarily which increases gas cost.
Using storage which is invalid for function parameters.
4fill in blank
hard

Fill the blank to create a temporary memory array for the function return. Mappings are always stored in storage.

Blockchain / Solidity
mapping(address => uint) balances;
function getTopBalances() public view returns (uint[] {{BLANK_2}}) {}
Drag options to blanks, or click blank then click option'
Astorage
Bcalldata
Cmemory
Dpersistent
Attempts:
3 left
💡 Hint
Common Mistakes
Declaring mapping as memory which is invalid.
Returning arrays without specifying memory location.
5fill in blank
hard

Fill both blanks to declare a memory struct variable and assign a value.

Blockchain / Solidity
struct User {
    uint id;
    string name;
}
User [2] userMemory;
userMemory.id = {{BLANK_3}};
Drag options to blanks, or click blank then click option'
Astorage
Bmemory
C10
Dcalldata
Attempts:
3 left
💡 Hint
Common Mistakes
Declaring struct with memory keyword which is invalid.
Assigning a string instead of a number to id.