0
0
Blockchain / Solidityprogramming~30 mins

Transfer and approve flow in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Transfer and approve flow
📖 Scenario: You are building a simple blockchain token system where users can transfer tokens to each other and approve others to spend tokens on their behalf.
🎯 Goal: Create a basic token transfer and approval flow using a dictionary to track balances and allowances.
📋 What You'll Learn
Create a dictionary called balances with exact user balances
Create a dictionary called allowances to track approved spending
Write a function transfer to move tokens between users
Write a function approve to set spending allowance
Write a function transfer_from to spend tokens using allowance
Print the final balances after transfers and approvals
💡 Why This Matters
🌍 Real World
This project models how cryptocurrencies and tokens manage transfers and approvals on blockchains.
💼 Career
Understanding transfer and approve flows is essential for blockchain developers working on smart contracts and token standards.
Progress0 / 4 steps
1
Set up initial balances
Create a dictionary called 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 exactly as shown.

2
Set up allowances dictionary
Create an empty dictionary called allowances to track approved spending.
Blockchain / Solidity
Need a hint?

Use empty curly braces to create an empty dictionary.

3
Write transfer, approve, and transfer_from functions
Write three functions: transfer(sender, receiver, amount) to move tokens if sender has enough balance; approve(owner, spender, amount) to set allowance; and transfer_from(spender, owner, receiver, amount) to transfer tokens using allowance if allowed and owner has enough balance.
Blockchain / Solidity
Need a hint?

Use dictionary methods like get to safely access balances and allowances.

4
Perform transfers, approvals, and print final balances
Call transfer('Alice', 'Bob', 20), then approve('Bob', 'Charlie', 15), then transfer_from('Charlie', 'Bob', 'Alice', 10). Finally, print the balances dictionary.
Blockchain / Solidity
Need a hint?

Make sure to call the functions in the correct order and print the balances dictionary.