0
0
Blockchain / Solidityprogramming~20 mins

Why data location affects cost in Blockchain / Solidity - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Blockchain Data Cost Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why does storing data on-chain cost more than off-chain?

In blockchain systems, storing data directly on the blockchain (on-chain) is often more expensive than storing it outside the blockchain (off-chain). Why is this the case?

ABecause off-chain data is encrypted, making it cheaper to store
BBecause on-chain data is stored in a centralized server, which charges fees
CBecause on-chain data must be stored by every node, increasing resource use and cost
DBecause off-chain data is stored in the cloud, which is always free
Attempts:
2 left
💡 Hint

Think about how blockchain nodes keep copies of the data.

Predict Output
intermediate
2:00remaining
What is the output of this blockchain storage cost calculation?

Consider this simplified Python code that calculates cost based on data size and location:

def storage_cost(size_kb, location):
    base_cost = 0.01  # base cost per KB
    if location == 'on-chain':
        multiplier = 10  # on-chain storage is 10x more expensive
    else:
        multiplier = 1
    return size_kb * base_cost * multiplier

print(storage_cost(100, 'on-chain'))

What is the output?

A0.1
B1.0
C100.0
D10.0
Attempts:
2 left
💡 Hint

Multiply size by base cost and multiplier.

🔧 Debug
advanced
2:30remaining
Identify the error in this blockchain data cost function

Here is a Python function to calculate storage cost. It should return the cost for given data size and location. Find the error that causes it to always return size_mb * 0.05.

def calc_cost(size_mb, location):
    cost_per_mb = 0.05
    if location == 'on-chain':
        cost_per_mb * 20
    else:
        cost_per_mb * 1
    return size_mb * cost_per_mb

print(calc_cost(5, 'on-chain'))
AThe multiplier is not assigned back to cost_per_mb, so cost_per_mb stays 0.05
BThe function uses size_mb instead of size_kb, causing wrong calculation
CThe return statement is missing parentheses
DThe if condition uses '==' instead of '=' causing syntax error
Attempts:
2 left
💡 Hint

Look at how the multiplier is applied to cost_per_mb.

📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in this smart contract snippet?

Given this Solidity-like pseudocode snippet for storing data location:

mapping(address => string) public dataLocation;

function setDataLocation(address user, string memory location) public {
    dataLocation[user] = location
}

Which option below will cause a syntax error?

AMissing semicolon after assignment: dataLocation[user] = location
BUsing 'memory' keyword with string parameter
CUsing 'public' visibility for mapping
DFunction missing return type
Attempts:
2 left
💡 Hint

Check punctuation at the end of statements.

🚀 Application
expert
3:00remaining
How does data location affect transaction fees in blockchain?

Imagine a blockchain where storing 1 KB on-chain costs 0.02 tokens, and storing 1 KB off-chain costs 0.001 tokens. A user wants to store 500 KB of data. They can choose to store all on-chain, all off-chain, or split 300 KB on-chain and 200 KB off-chain.

Which option results in the lowest total cost?

A300 KB off-chain + 200 KB on-chain: 4.3 tokens
BAll 500 KB off-chain: 0.5 tokens
C300 KB on-chain + 200 KB off-chain: 6.2 tokens
DAll 500 KB on-chain: 10 tokens
Attempts:
2 left
💡 Hint

Calculate cost for each scenario by multiplying size by cost per KB.