0
0
Blockchain / Solidityprogramming~30 mins

Public vs private blockchains - Hands-On Comparison

Choose your learning style9 modes available
Understanding Public vs Private Blockchains
📖 Scenario: You are learning about blockchains. Blockchains can be public or private. Public blockchains let anyone join and see all transactions. Private blockchains only allow certain people to join and see transactions.We will create simple data to represent users and transactions in both types of blockchains.
🎯 Goal: Build a simple program that stores users and transactions for a public blockchain and a private blockchain. Then filter transactions visible to a user based on blockchain type.
📋 What You'll Learn
Create a list of users for the public blockchain
Create a list of users for the private blockchain
Create a list of transactions with user names and amounts
Filter transactions visible to a user based on blockchain type
Print the visible transactions for a given user
💡 Why This Matters
🌍 Real World
Understanding who can see transactions in different blockchain types helps build secure and private blockchain applications.
💼 Career
Blockchain developers must know how to manage access and visibility of data in public and private blockchains.
Progress0 / 4 steps
1
Create user lists for public and private blockchains
Create a list called public_users with these exact names: 'Alice', 'Bob', 'Charlie'. Then create a list called private_users with these exact names: 'Dave', 'Eve'.
Blockchain / Solidity
Need a hint?

Use square brackets [] to create lists. Separate names with commas.

2
Create a list of transactions
Create a list called transactions with these exact dictionaries: {'user': 'Alice', 'amount': 50}, {'user': 'Dave', 'amount': 100}, {'user': 'Bob', 'amount': 75}, {'user': 'Eve', 'amount': 200}.
Blockchain / Solidity
Need a hint?

Use a list of dictionaries. Each dictionary has keys 'user' and 'amount'.

3
Filter visible transactions for a user
Create a variable called user and set it to 'Bob'. Create a variable called blockchain_type and set it to 'public'. Then create a list called visible_transactions that includes only transactions where the 'user' is in public_users if blockchain_type is 'public', or in private_users if blockchain_type is 'private'.
Blockchain / Solidity
Need a hint?

Use an if statement to check blockchain_type. Use a list comprehension to filter transactions.

4
Print visible transactions for the user
Write a print statement to display the list visible_transactions.
Blockchain / Solidity
Need a hint?

Use print(visible_transactions) to show the filtered list.