0
0
Blockchain / Solidityprogramming~30 mins

Cross-chain bridges in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Cross-chain Bridges Basics
📖 Scenario: You are building a simple program to track token transfers between two blockchains using a cross-chain bridge. This helps users move tokens safely from one chain to another.
🎯 Goal: Create a program that stores token balances on two chains, sets a minimum transfer amount, processes transfers only if they meet the minimum, and shows the updated balances.
📋 What You'll Learn
Create a dictionary called chain_balances with exact keys 'ChainA' and 'ChainB' and initial balances 1000 and 500 respectively
Create a variable called min_transfer and set it to 100
Write a function called transfer_tokens that takes amount and transfers tokens from 'ChainA' to 'ChainB' only if amount is greater than or equal to min_transfer
Print the updated chain_balances after a transfer of 150 tokens
💡 Why This Matters
🌍 Real World
Cross-chain bridges let users move tokens between different blockchains, enabling more flexible and powerful blockchain applications.
💼 Career
Understanding how to track and control token transfers across chains is important for blockchain developers working on decentralized finance (DeFi) and interoperability solutions.
Progress0 / 4 steps
1
Set up initial chain balances
Create a dictionary called chain_balances with keys 'ChainA' and 'ChainB' having values 1000 and 500 respectively.
Blockchain / Solidity
Need a hint?

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

2
Set minimum transfer amount
Create a variable called min_transfer and set it to 100.
Blockchain / Solidity
Need a hint?

Just assign the number 100 to the variable min_transfer.

3
Write transfer function
Write a function called transfer_tokens that takes a parameter amount. Inside the function, check if amount is greater than or equal to min_transfer. If yes, subtract amount from chain_balances['ChainA'] and add it to chain_balances['ChainB']. If not, do nothing.
Blockchain / Solidity
Need a hint?

Use def to create the function and an if statement to check the amount.

4
Perform transfer and show balances
Call the function transfer_tokens with 150 as the argument. Then print the chain_balances dictionary to show updated balances.
Blockchain / Solidity
Need a hint?

Call the function with 150 and then print the dictionary to see the new balances.