0
0
Blockchain / Solidityprogramming~10 mins

Why data location affects cost in Blockchain / Solidity - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why data location affects cost
User wants to store data
Choose data location
Check storage cost per location
Calculate total cost
Decide to store or not
Store data
Cancel storage
Data location affects cost because different blockchain storage options charge differently based on where data is stored.
Execution Sample
Blockchain / Solidity
storage_costs = {"on_chain": 10, "off_chain": 2}
data_size = 5
location = "on_chain"
total_cost = storage_costs[location] * data_size
print(total_cost)
Calculates total cost to store data based on chosen location and data size.
Execution Table
StepVariableValueActionOutput
1storage_costs{"on_chain": 10, "off_chain": 2}Define cost per unit data
2data_size5Define data size to store
3location"on_chain"Choose data location
4total_coststorage_costs["on_chain"] * 5Calculate total cost50
5print(total_cost)Output total cost50
💡 Calculation done and cost output printed
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
storage_costsundefined{"on_chain": 10, "off_chain": 2}{"on_chain": 10, "off_chain": 2}{"on_chain": 10, "off_chain": 2}{"on_chain": 10, "off_chain": 2}{"on_chain": 10, "off_chain": 2}
data_sizeundefinedundefined5555
locationundefinedundefinedundefined"on_chain""on_chain""on_chain"
total_costundefinedundefinedundefinedundefined5050
Key Moments - 2 Insights
Why does choosing 'on_chain' cost more than 'off_chain'?
Because 'on_chain' storage cost per unit is 10, higher than 'off_chain' which is 2, as shown in execution_table step 4 calculation.
What happens if data_size changes?
Total cost changes proportionally since total_cost = cost_per_unit * data_size, as seen in step 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 4, what is the total_cost value?
A10
B50
C5
D2
💡 Hint
Check the 'Value' column for total_cost at step 4 in execution_table.
At which step is the data location chosen?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look for the step where 'location' variable is assigned in execution_table.
If data_size was 10 instead of 5, what would total_cost be at step 4?
A100
B50
C20
D10
💡 Hint
Multiply storage_costs['on_chain'] (10) by new data_size (10) as in step 4 calculation.
Concept Snapshot
Data location affects cost because different storage options charge differently.
Cost = cost_per_unit * data_size.
On-chain storage is usually more expensive than off-chain.
Choosing location impacts total cost directly.
Always calculate cost before storing data.
Full Transcript
This visual execution shows how data location affects cost in blockchain storage. First, storage costs per location are defined. Then, data size and location are chosen. The total cost is calculated by multiplying cost per unit by data size. Finally, the cost is printed. On-chain storage costs more per unit than off-chain, so total cost depends on location and data size.