0
0
Blockchain / Solidityprogramming~10 mins

Storage layout 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 in Solidity.

Blockchain / Solidity
contract Storage {
    uint256 public [1];
}
Drag options to blanks, or click blank then click option'
AstorageValue
BmemoryVar
Ctemp
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'memoryVar' which suggests memory instead of storage.
Using temporary names like 'temp' which are unclear.
2fill in blank
medium

Complete the code to read a storage variable inside a function.

Blockchain / Solidity
contract Storage {
    uint256 public storedData;
    function getData() public view returns (uint256) {
        return [1];
    }
}
Drag options to blanks, or click blank then click option'
AstoredData()
Bthis.storedData
CstoredData
DgetData
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'storedData()' which is incorrect syntax for variables.
Using 'getData' which is the function name, not the variable.
3fill in blank
hard

Fix the error in the code to correctly update a storage variable.

Blockchain / Solidity
contract Storage {
    uint256 public count;
    function increment() public {
        count [1] 1;
    }
}
Drag options to blanks, or click blank then click option'
A=
B+=
C-=
D*=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which replaces the value instead of adding.
Using '-=' which decreases the value.
4fill in blank
hard

Fill both blanks to declare and initialize a mapping in storage.

Blockchain / Solidity
contract Storage {
    mapping(address => [1]) public balances;
    function setBalance(address user, uint256 amount) public {
        balances[user] [2] amount;
    }
}
Drag options to blanks, or click blank then click option'
Auint256
B=
C+=
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' which adds to the existing value instead of setting it.
Using 'address' as the value type instead of 'uint256'.
5fill in blank
hard

Fill both blanks to create a struct, declare a storage variable, and update its field.

Blockchain / Solidity
contract Storage {
    struct User  { {
        uint256 id;
        string name;
    }
    User public {BLANK_2}};
    function setUser(uint256 _id, string memory _name) public {
        [2].id = _id;
        {{BLANK_3}}.name = _name;
    }
}
Drag options to blanks, or click blank then click option'
A {
Buser
DUser
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the opening brace '{' after struct name.
Using 'User' instead of the variable name when updating fields.