Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Layer 2 Solutions Overview
📖 Scenario: You are working with blockchain data and want to organize information about Layer 2 solutions. Layer 2 solutions help blockchains handle more transactions quickly and cheaply by working on top of the main blockchain.
🎯 Goal: You will create a dictionary of Layer 2 solutions with their types, set a filter type, extract solutions of that type using dictionary comprehension, and finally print the filtered solutions.
📋 What You'll Learn
Create a dictionary called layer2_solutions with exact entries for solutions and their types
Create a variable called filter_type with the exact string value to filter solutions
Use dictionary comprehension to create a new dictionary called filtered_solutions containing only solutions matching filter_type
Print the filtered_solutions dictionary
💡 Why This Matters
🌍 Real World
Layer 2 solutions are important in blockchain to improve speed and reduce costs. Organizing and filtering these solutions helps developers and users understand options available.
💼 Career
Understanding how to manage and filter data structures like dictionaries is essential for blockchain developers working with Layer 2 technologies and other blockchain data.
Progress0 / 4 steps
1
Create the Layer 2 solutions dictionary
Create a dictionary called layer2_solutions with these exact entries: 'Optimism': 'Optimistic Rollup', 'Arbitrum': 'Optimistic Rollup', 'Polygon': 'Sidechain', 'zkSync': 'ZK Rollup', 'Loopring': 'ZK Rollup'
Blockchain / Solidity
Hint
Use curly braces {} to create a dictionary with keys and values separated by colons.
2
Set the filter type
Create a variable called filter_type and set it to the string 'Optimistic Rollup'
Blockchain / Solidity
Hint
Assign the string 'Optimistic Rollup' to the variable filter_type.
3
Filter solutions by type using dictionary comprehension
Use dictionary comprehension to create a new dictionary called filtered_solutions that contains only the entries from layer2_solutions where the value equals filter_type
Blockchain / Solidity
Hint
Use a dictionary comprehension with a condition to filter by filter_type.
4
Print the filtered solutions
Write a print statement to display the filtered_solutions dictionary
Blockchain / Solidity
Hint
Use print(filtered_solutions) to show the filtered dictionary.
Practice
(1/5)
1. What is the main purpose of Layer 2 solutions in blockchain?
easy
A. To create new cryptocurrencies
B. To replace the main blockchain entirely
C. To store large files on the blockchain
D. To increase transaction speed and reduce costs by processing off the main chain
Solution
Step 1: Understand Layer 2 role
Layer 2 solutions are designed to handle more transactions faster and cheaper by working off the main blockchain.
Step 2: Compare options
Options A, B, and D describe unrelated blockchain functions, while C correctly states Layer 2's purpose.
Final Answer:
To increase transaction speed and reduce costs by processing off the main chain -> Option D
Quick Check:
Layer 2 purpose = Speed and cost efficiency [OK]
Hint: Layer 2 = faster, cheaper transactions off main chain [OK]
Common Mistakes:
Thinking Layer 2 replaces the main blockchain
Confusing Layer 2 with creating new coins
Assuming Layer 2 stores large files
2. Which of the following is a correct example of a Layer 2 solution?
easy
A. State channels
B. Proof of Work consensus
C. Smart contracts on main chain
D. Mining pools
Solution
Step 1: Identify Layer 2 examples
Common Layer 2 solutions include state channels, rollups, and sidechains.
Step 2: Match options to Layer 2
State channels are Layer 2; Proof of Work and mining pools relate to Layer 1; smart contracts run on main chain, not Layer 2.
Final Answer:
State channels -> Option A
Quick Check:
Layer 2 example = State channels [OK]
Hint: State channels are classic Layer 2 solutions [OK]
Common Mistakes:
Confusing consensus methods with Layer 2
Thinking smart contracts are Layer 2
Mixing mining pools with Layer 2
3. Consider this simplified code snippet representing a rollup process:
A. update() is not a method of dict, use state_channel = update
B. update() is a method but state_channel.update(update) modifies dict correctly, no error
C. update() is a method but should be called with parentheses as done, no fix needed
D. No error, output is 50
Solution
Step 1: Check dict update method usage
Python dict has an update() method that merges another dict into it, called correctly here.
Step 2: Confirm output after update
state_channel's 'balance' key is updated from 100 to 50, so print outputs 50 without error.
Final Answer:
update() is a method but state_channel.update(update) modifies dict correctly, no error -> Option B
Quick Check:
Dict update method works as expected [OK]
Hint: dict.update() merges keys, no error if used correctly [OK]
Common Mistakes:
Thinking update() is not a dict method
Confusing assignment with update method
Expecting syntax error on update() call
5. You want to design a Layer 2 solution that bundles multiple transactions off-chain and submits a single proof to the main chain. Which Layer 2 type fits best and why?
hard
A. Rollups, because they bundle transactions and submit proofs to main chain
B. State channels, because they keep transactions private between participants
C. Sidechains, because they run a separate blockchain with their own consensus
D. Mining pools, because they combine mining power
Solution
Step 1: Understand Layer 2 types
Sidechains run separate blockchains; state channels keep private off-chain transactions; rollups bundle transactions and submit proofs on-chain.
Step 2: Match requirement to Layer 2 type
Bundling multiple transactions off-chain and submitting a single proof matches rollups' design.
Final Answer:
Rollups, because they bundle transactions and submit proofs to main chain -> Option A
Quick Check:
Bundling + proof submission = Rollups [OK]
Hint: Rollups bundle transactions and post proofs on main chain [OK]