Storage is a persistent place where data is saved on the blockchain. It keeps data between function calls and transactions, but it costs more gas to use.
Click to reveal answer
beginner
What does memory mean in smart contract functions?
Memory is a temporary place to hold data during a function call. It is erased after the function finishes and costs less gas than storage.
Click to reveal answer
intermediate
Explain calldata in the context of smart contracts.
Calldata is a special read-only area where function arguments are stored. It is cheaper than memory and storage and cannot be changed inside the function.
Click to reveal answer
beginner
Which data location is the most expensive to use in terms of gas?
Storage is the most expensive because it saves data permanently on the blockchain.
Click to reveal answer
intermediate
When should you use memory instead of storage?
Use memory when you only need data temporarily inside a function and don't want to save it permanently. This saves gas.
Click to reveal answer
Which data location is read-only and cheaper than memory?
AMemory
BStorage
CCalldata
DStack
✗ Incorrect
Calldata is read-only and cheaper than memory because it holds function arguments without copying them.
Where is data stored permanently in a smart contract?
AStorage
BCalldata
CMemory
DCache
✗ Incorrect
Storage saves data permanently on the blockchain, unlike memory or calldata.
Which data location is erased after a function call ends?
AMemory
BDisk
CCalldata
DStorage
✗ Incorrect
Memory is temporary and erased after the function finishes.
Why should you avoid using storage for temporary data?
AIt cannot hold complex data
BIt is slower to access
CIt is read-only
DIt costs more gas
✗ Incorrect
Storage costs more gas because it writes data permanently to the blockchain.
Which data location is best for passing function arguments without modification?
AStorage
BCalldata
CMemory
DHeap
✗ Incorrect
Calldata is ideal for passing arguments because it is read-only and cheaper.
Describe the differences between storage, memory, and calldata in smart contracts.
Think about cost, lifetime, and mutability of data.
You got /4 concepts.
Explain why choosing the right data location matters for gas costs in blockchain programming.
Consider how long data lives and how often it changes.
You got /4 concepts.
Practice
(1/5)
1. Which of the following correctly describes storage in Solidity?
easy
A. It stores data permanently on the blockchain.
B. It holds temporary data only during function execution.
C. It is used for read-only input data in external functions.
D. It is a type of event logging mechanism.
Solution
Step 1: Understand storage role
storage variables are saved permanently on the blockchain and persist between function calls.
Step 2: Compare with memory and calldata
memory is temporary during function execution, and calldata is read-only input data for external functions.
Final Answer:
It stores data permanently on the blockchain. -> Option A
Quick Check:
Storage = permanent data [OK]
Hint: Storage is permanent, memory is temporary, calldata is input [OK]
Common Mistakes:
Confusing storage with memory as temporary
Thinking calldata can be modified
Assuming storage is read-only
2. Which keyword is used to declare a function parameter that is read-only and passed from an external caller?
easy
A. calldata
B. storage
C. memory
D. event
Solution
Step 1: Identify parameter data location for external input
Function parameters from external callers that should not be modified use calldata.
Step 2: Recall other data locations
memory is for temporary data inside functions, storage is persistent, and event is unrelated to data location.
Final Answer:
calldata -> Option A
Quick Check:
External input = calldata [OK]
Hint: External read-only params use calldata [OK]
Common Mistakes:
Using memory for external parameters
Confusing event with data location
Using storage for function parameters
3. What will be the output of this Solidity function when called externally with _data = [1, 2, 3]?
function process(uint[] calldata _data) external pure returns (uint) {
uint sum = 0;
for (uint i = 0; i < _data.length; i++) {
sum += _data[i];
}
return sum;
}
medium
A. Runtime error
B. 6
C. Compilation error
D. 0
Solution
Step 1: Understand calldata usage
The function receives an array _data as calldata, which is read-only but accessible for reading elements.
Step 2: Calculate sum of array elements
Sum of [1, 2, 3] is 1 + 2 + 3 = 6, which is returned.
Final Answer:
6 -> Option B
Quick Check:
Sum of input array = 6 [OK]
Hint: Sum array elements from calldata works like memory [OK]
Common Mistakes:
Thinking calldata cannot be read
Expecting compilation error due to calldata
Confusing sum calculation logic
4. Identify the error in this Solidity function:
function updateData(uint[] calldata _input) external {
_input[0] = 10;
}
medium
A. Calldata arrays cannot be passed as parameters.
B. Function must be marked pure.
C. Missing return statement.
D. Cannot assign to calldata array elements.
Solution
Step 1: Check mutability of calldata
calldata is read-only, so assigning to _input[0] causes an error.
Step 2: Validate other options
The function can be non-pure, no return needed, and calldata arrays are allowed as parameters.
Final Answer:
Cannot assign to calldata array elements. -> Option D
Quick Check:
Calldata is read-only [OK]
Hint: Calldata arrays are read-only, no assignment allowed [OK]
Common Mistakes:
Trying to modify calldata elements
Thinking pure is required here
Assuming return is mandatory
5. You want to write a Solidity function that accepts a large array from an external caller, processes it temporarily, and then stores the result permanently. Which combination of data locations should you use for the parameter and the storage variable?
hard
A. Parameter as memory, storage variable as calldata
B. Parameter as storage, storage variable as memory
C. Parameter as calldata, storage variable as storage
D. Parameter as calldata, storage variable as memory
Solution
Step 1: Choose parameter data location for large external input
calldata is efficient and read-only for large external arrays, avoiding unnecessary copying.
Step 2: Choose storage variable for permanent data
To keep data permanently on blockchain, use storage for the variable that stores the processed result.
Final Answer:
Parameter as calldata, storage variable as storage -> Option C
Quick Check:
External input = calldata, permanent store = storage [OK]
Hint: Use calldata for input, storage for permanent save [OK]
Common Mistakes:
Using memory for large external input (inefficient)
Trying to store permanent data in memory or calldata
Confusing storage and memory roles
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.