📖 Scenario: Imagine you want to send digital money to your friend without using a bank. Blockchain helps you do this safely and clearly by handling the value (money) directly between you and your friend.
🎯 Goal: Build a simple program that shows how blockchain handles value by recording transactions between people.
📋 What You'll Learn
Create a list of transactions with sender, receiver, and amount
Add a variable to track the minimum amount to record
Use a loop to filter transactions above the minimum amount
Print the filtered transactions showing value handled
💡 Why This Matters
🌍 Real World
Blockchain is used to securely transfer money or assets without banks. Handling value correctly is key to trust and transparency.
💼 Career
Understanding how value is handled in blockchain helps in jobs like blockchain developer, financial software engineer, and security analyst.
Progress0 / 4 steps
1
Create the initial list of transactions
Create a list called transactions with these exact dictionaries: {'sender': 'Alice', 'receiver': 'Bob', 'amount': 50}, {'sender': 'Bob', 'receiver': 'Charlie', 'amount': 30}, {'sender': 'Alice', 'receiver': 'David', 'amount': 70}
Blockchain / Solidity
Hint
Use a list with dictionaries inside. Each dictionary has keys 'sender', 'receiver', and 'amount'.
2
Add a minimum amount filter
Create a variable called min_amount and set it to 40 to filter transactions with amounts greater than or equal to this value
Blockchain / Solidity
Hint
Just create a variable named min_amount and set it to 40.
3
Filter transactions by minimum amount
Create a list called filtered_transactions using a list comprehension that includes only transactions from transactions where the amount is greater than or equal to min_amount
Blockchain / Solidity
Hint
Use a list comprehension to pick transactions where the amount is at least min_amount.
4
Print the filtered transactions
Write a print statement to display the filtered_transactions list
Blockchain / Solidity
Hint
Use print(filtered_transactions) to show the result.
Practice
(1/5)
1. Why is handling value considered core to blockchain technology?
easy
A. Because blockchains enable secure transfer of money or assets between people.
B. Because blockchains only store text data without any value.
C. Because blockchains are used only for social media applications.
D. Because blockchains do not require any authorization for transactions.
Solution
Step 1: Understand blockchain purpose
Blockchains are designed to let people send money or assets safely.
Step 2: Identify role of value handling
Handling value is essential because it allows secure and trusted transfer of assets.
Final Answer:
Because blockchains enable secure transfer of money or assets between people. -> Option A
Quick Check:
Value handling = secure asset transfer [OK]
Hint: Value handling means secure asset transfer on blockchain [OK]
Common Mistakes:
Thinking blockchain only stores text data
Assuming no authorization is needed
Confusing blockchain with social media
2. Which of the following is the correct way to represent a transaction value in a blockchain smart contract?
easy
A. let value = 100; // as a number
B. let value = null; // as null
C. let value = true; // as a boolean
D. let value = '100'; // as a string
Solution
Step 1: Identify correct data type for value
Transaction values represent amounts, so they should be numbers, not strings or booleans.
Step 2: Check each option
let value = 100; // as a number uses a number type which is correct for value representation.
Final Answer:
let value = 100; // as a number -> Option A
Quick Check:
Value must be a number [OK]
Hint: Transaction value must be a number, not string or boolean [OK]
Common Mistakes:
Using strings to represent numeric values
Using booleans or null for amounts
Confusing data types in smart contracts
3. Consider this simplified blockchain transaction code snippet:
let senderBalance = 500;
let transferAmount = 200;
if (senderBalance >= transferAmount) {
senderBalance -= transferAmount;
receiverBalance += transferAmount;
}
console.log(senderBalance);
What will be the output?
medium
A. 700
B. 300
C. 500
D. 200
Solution
Step 1: Check condition and initial values
senderBalance is 500, transferAmount is 200, condition senderBalance >= transferAmount is true.
Step 2: Calculate new senderBalance
senderBalance is reduced by 200, so 500 - 200 = 300.
Final Answer:
300 -> Option B
Quick Check:
500 - 200 = 300 [OK]
Hint: Subtract transfer amount from sender balance if enough funds [OK]
Common Mistakes:
Adding instead of subtracting transfer amount
Ignoring the condition check
Confusing sender and receiver balances
4. The following code tries to update balances after a transaction but has a bug:
let senderBalance = 300;
let receiverBalance = 100;
let transferAmount = 400;
if (senderBalance > transferAmount) {
senderBalance -= transferAmount;
receiverBalance += transferAmount;
}
console.log(senderBalance);
What is the bug and how to fix it?
medium
A. The senderBalance should be increased, not decreased.
B. The transferAmount should be less than senderBalance, so no fix needed.
C. The receiverBalance update is missing a semicolon.
D. The condition should be senderBalance >= transferAmount to allow exact balance transfer.
Solution
Step 1: Analyze the condition
The condition uses > which excludes the case when senderBalance equals transferAmount.
Step 2: Correct the condition
Change > to >= so sender can transfer all their balance exactly.
Final Answer:
The condition should be senderBalance >= transferAmount to allow exact balance transfer. -> Option D
Quick Check:
Use >= to allow full balance transfer [OK]
Hint: Use >= to allow transfer of full sender balance [OK]
Common Mistakes:
Using > excludes exact balance transfers
Ignoring condition logic
Misunderstanding balance updates
5. You want to create a function that safely transfers value between two accounts on a blockchain. Which approach best ensures the transaction is valid and balances update correctly?
hard
A. Add amount to receiver first, then subtract from sender without checks.
B. Subtract amount from sender without checking balance, then add to receiver.
C. Check sender balance >= amount, subtract amount from sender, add to receiver, then record transaction.
D. Record transaction first, then update balances without validation.
Solution
Step 1: Validate sender has enough balance
Checking sender balance >= amount prevents overspending and errors.
Step 2: Update balances and record transaction
Subtract from sender, add to receiver, then record transaction to keep system consistent.
Final Answer:
Check sender balance >= amount, subtract amount from sender, add to receiver, then record transaction. -> Option C
Quick Check:
Validate then update balances then record [OK]
Hint: Validate balance before transfer, then update and record [OK]
Common Mistakes:
Updating balances without validation
Recording transaction before balance update
Adding to receiver before subtracting from sender
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.