Unit 4 – Structure of Blockchain · 49
Data Storage
Solidity distinguishes persistent storage, temporary memory and call-scoped calldata. Storage survives between transactions, memory is temporary during execution, and calldata is a read-only input area commonly used for external function arguments.
Animated diagram
Storage is a filing cabinet, memory is a desk used while working, and calldata is a read-only document delivered with the request
The idea in one line
Make the invisible feel visible.
Solidity distinguishes persistent storage, temporary memory and call-scoped calldata. Storage survives between transactions, memory is temporary during execution, and calldata is a read-only input area commonly used for external function arguments.
Real-life lens
Think of it like this
Storage is a filing cabinet, memory is a desk used while working, and calldata is a read-only document delivered with the request.
Under the hood
How it works, step by step
Start with the idea
Solidity distinguishes persistent storage, temporary memory and call-scoped calldata. Storage survives between transactions, memory is temporary during execution, and calldata is a read-only input area commonly used for external function arguments.
Follow the example
A function can read an array from calldata, calculate a result in memory and save only a final value to storage.
Notice the benefit
Choosing the right data location can make intent clearer and reduce unnecessary execution cost.
Check the limitation
Storage layout and writes have gas and upgrade implications; confusing data locations can create bugs or unexpectedly high costs.
Make it concrete
Data Storage in practice
Data Storage in practice
A function can read an array from calldata, calculate a result in memory and save only a final value to storage.
Key point: Storage layout and writes have gas and upgrade implications; confusing data locations can create bugs or unexpectedly high costs.
Balanced view
Advantages & disadvantages
Advantages
- Choosing the right data location can make intent clearer and reduce unnecessary execution cost.
Disadvantages
- Storage layout and writes have gas and upgrade implications; confusing data locations can create bugs or unexpectedly high costs.
Keep these close
Takeaways & common traps
What to remember
- Solidity distinguishes persistent storage, temporary memory and call-scoped calldata. Storage survives between transactions, memory is temporary during execution, and calldata is a read-only input area commonly used for external function arguments.
- Choosing the right data location can make intent clearer and reduce unnecessary execution cost.
- Storage layout and writes have gas and upgrade implications; confusing data locations can create bugs or unexpectedly high costs.
Watch out for
- Do not assume data storage guarantees more than its design can prove.
- Do not ignore the trade-off: Storage layout and writes have gas and upgrade implications; confusing data locations can create bugs or unexpectedly high costs.
Quick check
Questions people ask
Why is data storage useful?
Choosing the right data location can make intent clearer and reduce unnecessary execution cost.
What is an important limitation?
Storage layout and writes have gas and upgrade implications; confusing data locations can create bugs or unexpectedly high costs.