Sidechains in Blockchain / Solidity - Mini Project: Build & Apply
Start learning this pattern below
Jump into concepts and practice - no test required
main_chain_balances with these exact entries: 'Alice': 100, 'Bob': 50, 'Charlie': 75.Use curly braces {} to create a dictionary with keys and values.
sidechain_balances with the same keys as main_chain_balances but all values set to 0. Then create a variable called transfer_amount and set it to 20.Use the same keys as main_chain_balances but set all values to 0 for sidechain_balances.
Set transfer_amount to 20.
for loop using user to iterate over main_chain_balances. Inside the loop, subtract transfer_amount from main_chain_balances[user] and add transfer_amount to sidechain_balances[user].Use a for loop to update balances for each user.
for loop using user to iterate over sidechain_balances. Inside the loop, add transfer_amount back to main_chain_balances[user] and subtract transfer_amount from sidechain_balances[user]. Then print main_chain_balances and sidechain_balances.Use a for loop to move tokens back. Then print both dictionaries to see final balances.
Practice
What is the main purpose of a sidechain in blockchain technology?
Solution
Step 1: Understand sidechain function
Sidechains connect to a main blockchain to move assets safely without altering the main chain.Step 2: Compare options
Only To allow assets to move between blockchains without changing the main chain describes this purpose correctly; others describe unrelated functions.Final Answer:
To allow assets to move between blockchains without changing the main chain -> Option DQuick Check:
Sidechains move assets safely = C [OK]
- Thinking sidechains replace main blockchain
- Confusing sidechains with password storage
- Assuming sidechains speed up mining
Which of the following is the correct way to describe the process of moving assets from the main chain to a sidechain?
lockOnMainChain() and issueOnSidechain() are functions.
Solution
Step 1: Understand asset transfer steps
Assets are locked on the main chain first, then issued on the sidechain.Step 2: Match function order
lockOnMainChain(); issueOnSidechain();correctly callslockOnMainChain()beforeissueOnSidechain().Final Answer:
lockOnMainChain(); issueOnSidechain();-> Option BQuick Check:
Lock then issue = A [OK]
- Issuing before locking assets
- Using burn instead of lock for main chain
- Mixing function order
Consider this pseudocode for moving assets from a sidechain back to the main chain:
burnOnSidechain() unlockOnMainChain()
What will be the output if burnOnSidechain() fails?
Solution
Step 1: Analyze burn failure effect
IfburnOnSidechain()fails, assets are not removed from the sidechain.Step 2: Understand unlock condition
unlockOnMainChain()should only run after successful burn; if burn fails, unlock does not happen.Final Answer:
Assets remain locked on the main chain -> Option AQuick Check:
Burn must succeed before unlock = D [OK]
- Assuming unlock happens even if burn fails
- Thinking assets get duplicated
- Confusing burn with lock
Find the error in this pseudocode for transferring assets to a sidechain:
lockOnMainChain() issueOnSidechain() unlockOnMainChain()
Solution
Step 1: Review transfer steps
Assets must stay locked on the main chain until they are returned from the sidechain.Step 2: Identify incorrect unlock
Unlocking immediately after issuing breaks asset security; unlock should happen only when assets return.Final Answer:
Unlocking main chain assets immediately after issuing is incorrect -> Option AQuick Check:
Unlock only after return = A [OK]
- Unlocking main chain assets too soon
- Confusing issue with burn
- Reversing lock and issue order
You want to design a sidechain system that allows fast transactions but ensures no asset duplication. Which approach best achieves this?
Choose the correct sequence of actions when moving assets from main chain to sidechain and back.
Solution
Step 1: Understand asset safety steps
To avoid duplication, assets must be locked on the main chain before issuing on sidechain, and burned on sidechain before unlocking main chain.Step 2: Match correct sequence
Lock on main chain -> Issue on sidechain -> Burn on sidechain -> Unlock on main chain follows the correct order: lock -> issue -> burn -> unlock, ensuring assets exist only in one place at a time.Final Answer:
Lock on main chain -> Issue on sidechain -> Burn on sidechain -> Unlock on main chain -> Option CQuick Check:
Lock, issue, burn, unlock = B [OK]
- Issuing before locking assets
- Unlocking main chain too early
- Burning assets on wrong chain
