Why Security Prevents Financial Loss in Blockchain
📖 Scenario: Imagine you are building a simple blockchain system that keeps track of transactions. Each transaction has a sender, receiver, and amount. To keep the system safe, you want to check if a transaction is valid before adding it to the blockchain. Invalid transactions could cause financial loss.
🎯 Goal: You will create a small program that stores transactions, sets a minimum security threshold, filters out invalid transactions, and then shows only the safe transactions. This teaches how security checks help prevent financial loss.
📋 What You'll Learn
Create a dictionary called transactions with exact entries for senders, receivers, and amounts
Create a variable called min_amount to set the minimum allowed transaction amount
Use a dictionary comprehension to create a new dictionary secure_transactions that only includes transactions with amounts greater than or equal to min_amount
Print the secure_transactions dictionary to show the filtered safe transactions
💡 Why This Matters
🌍 Real World
In real blockchain systems, security checks prevent fraudulent or invalid transactions that could cause financial loss.
💼 Career
Understanding how to filter and validate data is essential for blockchain developers and security engineers to protect assets.
Progress0 / 4 steps
1
DATA SETUP: Create the transactions dictionary
Create a dictionary called transactions with these exact entries: "tx1": {"sender": "Alice", "receiver": "Bob", "amount": 50}, "tx2": {"sender": "Charlie", "receiver": "Dave", "amount": 20}, "tx3": {"sender": "Eve", "receiver": "Frank", "amount": 5}
Blockchain / Solidity
Hint
Use curly braces to create the dictionary. Each key is a string like "tx1" and each value is another dictionary with keys "sender", "receiver", and "amount".
2
CONFIGURATION: Set the minimum allowed transaction amount
Create a variable called min_amount and set it to 10 to represent the minimum secure transaction amount
Blockchain / Solidity
Hint
Just create a variable named min_amount and assign the number 10 to it.
3
CORE LOGIC: Filter transactions using dictionary comprehension
Use a dictionary comprehension to create a new dictionary called secure_transactions that includes only those transactions from transactions where the amount is greater than or equal to min_amount
Blockchain / Solidity
Hint
Use {key: value for key, value in transactions.items() if value["amount"] >= min_amount} to filter.
4
OUTPUT: Print the secure transactions
Write a print statement to display the secure_transactions dictionary
Blockchain / Solidity
Hint
Use print(secure_transactions) to show the filtered transactions.
Practice
(1/5)
1. Why is security important in blockchain to prevent financial loss?
easy
A. It increases the size of the blockchain.
B. It stops unauthorized people from accessing your digital money.
C. It makes transactions slower.
D. It allows anyone to change transaction history.
Solution
Step 1: Understand unauthorized access risk
Unauthorized access means someone can take your money without permission.
Step 2: Recognize security's role
Security prevents unauthorized access, protecting your digital assets.
Final Answer:
It stops unauthorized people from accessing your digital money. -> Option B
Quick Check:
Security prevents unauthorized access = C [OK]
Hint: Security blocks unauthorized access to your money [OK]
Common Mistakes:
Thinking security slows down transactions
Believing blockchain size affects security
Assuming anyone can change history
2. Which of the following is the correct way to verify a transaction in blockchain code?
easy
A. if transaction.verify(): process()
B. if verify(transaction): process()
C. verify if transaction process()
D. process() if verify transaction
Solution
Step 1: Identify correct method call syntax
In modern blockchain code, transactions have a verify() method called with dot notation.
Step 2: Check each option's syntax
if transaction.verify(): process() uses correct method call: transaction.verify(). Others have syntax errors.
Final Answer:
if transaction.verify(): process() -> Option A
Quick Check:
Method call syntax = B [OK]
Hint: Use dot notation for method calls like transaction.verify() [OK]
Common Mistakes:
Writing method calls without parentheses
Using wrong order of keywords
Missing dot between object and method
3. What will the following code output if the transaction is invalid?