Recall & Review
beginner
What is 'gas' in blockchain smart contracts?
Gas is the fee required to perform operations on a blockchain like Ethereum. It measures the computational effort needed to execute transactions or smart contracts.
Click to reveal answer
beginner
Why is storage expensive in smart contracts?
Storing data on the blockchain uses permanent space and requires more gas because it affects all nodes. Reading and writing storage costs more gas than using temporary memory.
Click to reveal answer
intermediate
How can packing variables reduce gas costs?
Packing multiple smaller variables into a single storage slot reduces the number of storage slots used, lowering gas costs because fewer storage operations are needed.
Click to reveal answer
intermediate
What is the benefit of using 'calldata' instead of 'memory' for function parameters?
Using 'calldata' for external function parameters avoids copying data into memory, saving gas because calldata is read-only and cheaper to access.
Click to reveal answer
beginner
Explain why minimizing storage writes saves gas.
Each write to storage costs a lot of gas. Minimizing writes by updating storage only when necessary or batching changes reduces gas consumption significantly.
Click to reveal answer
Which operation generally costs the most gas in a smart contract?
✗ Incorrect
Writing data to storage is the most expensive operation because it permanently changes the blockchain state.
What does 'packing variables' mean in gas optimization?
✗ Incorrect
Packing variables means placing multiple small variables into a single 32-byte storage slot to reduce storage usage.
Why is 'calldata' cheaper than 'memory' for function inputs?
✗ Incorrect
Calldata is cheaper because it is read-only and does not require copying data into memory.
Which of these reduces gas cost when updating storage?
✗ Incorrect
Batching updates reduces the number of storage writes, saving gas.
What is a common practice to save gas when dealing with boolean variables?
✗ Incorrect
Packing multiple booleans into one byte reduces storage slots used and saves gas.
Describe three ways to optimize gas costs related to storage in smart contracts.
Think about how data is stored and accessed in smart contracts.
You got /3 concepts.
Explain why storage operations are more expensive than memory operations in blockchain smart contracts.
Consider the difference between temporary and permanent data.
You got /3 concepts.