📖 Scenario: Imagine you want to keep a shared list of transactions that multiple friends can see and agree on. This shared list is called a distributed ledger. Each friend adds their transactions, and everyone can check the list to make sure it is correct.
🎯 Goal: You will build a simple distributed ledger using a list of dictionaries. Each dictionary will represent a transaction with a sender, receiver, and amount. You will add transactions, set a minimum amount to record, and then print the filtered transactions.
📋 What You'll Learn
Create a list called ledger with 3 specific transactions
Create a variable called min_amount set to 50
Use a list comprehension to create filtered_ledger with transactions having amount greater than or equal to min_amount
Print the filtered_ledger list
💡 Why This Matters
🌍 Real World
Distributed ledgers are used in blockchain to keep a shared, secure record of transactions that many people can trust without a central authority.
💼 Career
Understanding how to manage and filter transaction data is important for blockchain developers, data analysts, and software engineers working with decentralized systems.
Progress0 / 4 steps
1
Create the initial ledger with transactions
Create a list called ledger with these exact transactions as dictionaries: {'sender': 'Alice', 'receiver': 'Bob', 'amount': 100}, {'sender': 'Bob', 'receiver': 'Charlie', 'amount': 30}, and {'sender': 'Charlie', 'receiver': 'Alice', 'amount': 70}.
Blockchain / Solidity
Hint
Use a list with three dictionaries. Each dictionary has keys 'sender', 'receiver', and 'amount'.
2
Set the minimum amount to record
Create a variable called min_amount and set it to 50.
Blockchain / Solidity
Hint
Just create a variable named min_amount and assign the number 50.
3
Filter transactions by minimum amount
Use a list comprehension to create a new list called filtered_ledger that includes only transactions from ledger where the amount is greater than or equal to min_amount.
Blockchain / Solidity
Hint
Use a list comprehension with for tx in ledger and an if condition checking tx['amount'] >= min_amount.
4
Print the filtered ledger
Write a print statement to display the filtered_ledger list.
Blockchain / Solidity
Hint
Use print(filtered_ledger) to show the filtered transactions.
Practice
(1/5)
1. What is the main purpose of a distributed ledger in blockchain technology?
easy
A. To store data only on one central computer
B. To share data across many computers to keep it safe and clear
C. To allow only one person to control the data
D. To make data unreadable for everyone
Solution
Step 1: Understand the concept of distributed ledger
A distributed ledger shares data across many computers instead of one central place.
Step 2: Identify the main goal
This sharing keeps data safe and clear for everyone involved.
Final Answer:
To share data across many computers to keep it safe and clear -> Option B
Quick Check:
Distributed ledger = shared safe data [OK]
Hint: Distributed means data is shared, not stored in one place [OK]
Common Mistakes:
Thinking data is stored on a single computer
Believing one person controls the ledger
Confusing encryption with data sharing
2. Which of the following is the correct way to describe a block in a distributed ledger?
easy
A. A software program that controls the network
B. A single piece of data stored only on one computer
C. A secret key used to encrypt data
D. A group of transactions linked together and shared across the network
Solution
Step 1: Define what a block is in blockchain
A block is a group of transactions bundled together.
Step 2: Understand its role in the network
Blocks are linked and shared across the network to keep data consistent.
Final Answer:
A group of transactions linked together and shared across the network -> Option D
Quick Check:
Block = grouped shared transactions [OK]
Hint: Blocks group transactions and share them across the network [OK]
Common Mistakes:
Thinking a block is just one piece of data
Confusing blocks with encryption keys
Believing blocks are software programs
3. Consider a simple blockchain network where each block contains a hash of the previous block. If the first block's hash is 'abc123', and the second block's hash is calculated as hash('abc123' + 'data2'), what happens if someone tries to change 'data2' in the second block?
medium
A. The first block's hash changes automatically
B. Nothing changes because hashes are not linked
C. The hash of the second block changes, breaking the chain
D. The network ignores the change and continues
Solution
Step 1: Understand hash linking in blocks
Each block's hash depends on the previous block's hash and its own data.
Step 2: Effect of changing data in second block
Changing 'data2' changes the second block's hash, which breaks the chain's integrity.
Final Answer:
The hash of the second block changes, breaking the chain -> Option C
Quick Check:
Changing data breaks hash chain [OK]
Hint: Changing block data changes its hash, breaking the chain [OK]
Common Mistakes:
Thinking hashes are independent
Believing first block changes automatically
Assuming network ignores hash mismatches
4. A developer wrote this pseudocode for adding a new block to a distributed ledger:
A. The new hash should include the previous hash, not just data
B. The previous hash should be ignored when adding a block
C. The block should not store the previous hash
D. The ledger should be cleared before appending
Solution
Step 1: Review how block hashes are calculated
A block's hash must include the previous block's hash and its own data to link blocks securely.
Step 2: Identify the mistake in hash calculation
The code only hashes the data, missing the previous hash, breaking the chain security.
Final Answer:
The new hash should include the previous hash, not just data -> Option A
Quick Check:
Hash must include previous hash + data [OK]
Hint: Hash must combine previous hash and data to link blocks [OK]
Common Mistakes:
Hashing only data without previous hash
Ignoring previous hash in block structure
Clearing ledger unnecessarily
5. You want to design a distributed ledger system where multiple participants can add transactions, but only valid transactions are accepted after consensus. Which approach best ensures data integrity and trust in this system?
hard
A. Use a consensus algorithm that requires agreement from most participants before adding a block
B. Allow any participant to add blocks without checks to speed up the process
C. Store the ledger on a single trusted server controlled by one participant
D. Encrypt all transactions so no one can see the data
Solution
Step 1: Understand consensus in distributed ledgers
Consensus algorithms require most participants to agree on the data before adding it, ensuring trust.
Step 2: Evaluate options for data integrity and trust
Allowing unchecked additions or central control reduces trust; encryption alone doesn't ensure consensus.
Final Answer:
Use a consensus algorithm that requires agreement from most participants before adding a block -> Option A
Quick Check:
Consensus ensures trust and data integrity [OK]
Hint: Consensus means most agree before adding data [OK]
Common Mistakes:
Skipping consensus to speed up adding blocks
Centralizing ledger storage
Relying only on encryption without consensus
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.