0
0
Blockchain / Solidityprogramming~30 mins

Sidechains in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Sidechains
📖 Scenario: You are working on a blockchain project that uses sidechains to improve scalability and add new features without overloading the main blockchain.Sidechains are separate blockchains linked to the main chain, allowing assets to move between them securely.
🎯 Goal: Build a simple program that simulates transferring tokens from the main blockchain to a sidechain and back.This will help you understand how sidechains work in practice.
📋 What You'll Learn
Create a dictionary to represent the main blockchain balances
Create a dictionary to represent the sidechain balances
Create a variable for the transfer amount
Write code to move tokens from the main chain to the sidechain
Write code to move tokens back from the sidechain to the main chain
Print the final balances on both chains
💡 Why This Matters
🌍 Real World
Sidechains help blockchains handle more transactions and add new features without slowing down the main chain.
💼 Career
Understanding sidechains is useful for blockchain developers working on scalable and flexible blockchain solutions.
Progress0 / 4 steps
1
Create main blockchain balances
Create a dictionary called main_chain_balances with these exact entries: 'Alice': 100, 'Bob': 50, 'Charlie': 75.
Blockchain / Solidity
Need a hint?

Use curly braces {} to create a dictionary with keys and values.

2
Create sidechain balances and transfer amount
Create a dictionary called 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.
Blockchain / Solidity
Need a hint?

Use the same keys as main_chain_balances but set all values to 0 for sidechain_balances.

Set transfer_amount to 20.

3
Transfer tokens from main chain to sidechain
Write a 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].
Blockchain / Solidity
Need a hint?

Use a for loop to update balances for each user.

4
Transfer tokens back and print final balances
Write a 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.
Blockchain / Solidity
Need a hint?

Use a for loop to move tokens back. Then print both dictionaries to see final balances.