0
0
Blockchain / Solidityprogramming~10 mins

Packing variables for gas savings 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 packed struct with two uint128 variables.

Blockchain / Solidity
struct Data {
    uint128 a;
    uint128 [1];
}
Drag options to blanks, or click blank then click option'
Ae
Bc
Cd
Db
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that is not declared or inconsistent.
Using a type other than uint128 which affects packing.
2fill in blank
medium

Complete the code to pack three variables efficiently in a struct.

Blockchain / Solidity
struct Packed {
    uint64 x;
    uint64 y;
    [1] z;
}
Drag options to blanks, or click blank then click option'
Auint64
Buint32
Cuint128
Duint256
Attempts:
3 left
💡 Hint
Common Mistakes
Using a larger type like uint128 or uint256 which wastes space.
Using a smaller type like uint32 which may not be intended.
3fill in blank
hard

Fix the error in the struct to pack variables efficiently without wasting space.

Blockchain / Solidity
struct Example {
    uint256 a;
    uint128 [1];
    uint128 c;
}
Drag options to blanks, or click blank then click option'
Ab
Bd
Ce
Df
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that breaks naming conventions.
Misordering variables causing inefficient packing.
4fill in blank
hard

Fill both blanks to declare a struct with packed variables for gas savings.

Blockchain / Solidity
struct Storage {
    [1] flag;
    [2] count;
}
Drag options to blanks, or click blank then click option'
Abool
Buint256
Cuint8
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Using large types like uint256 unnecessarily.
Using types that do not pack well together.
5fill in blank
hard

Fill all three blanks to create a packed struct with an address and two small integers.

Blockchain / Solidity
struct PackedData {
    [1] owner;
    [2] level;
    [3] score;
}
Drag options to blanks, or click blank then click option'
Auint256
Buint8
Cuint16
Daddress
Attempts:
3 left
💡 Hint
Common Mistakes
Using large integer types for small values wastes gas.
Mixing types that do not pack well together.