Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

Why DeFi reimagines finance in Blockchain / Solidity - Challenge Your Understanding

Choose your learning style10 modes available

Start learning this pattern below

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
Challenge - 5 Problems
🎖️
DeFi Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this Solidity function for DeFi interest calculation?
Consider this Solidity function that calculates simple interest for a DeFi lending protocol. What is the output when principal = 1000, rate = 5, and time = 2?
Blockchain / Solidity
function calculateInterest(uint principal, uint rate, uint time) public pure returns (uint) {
    return (principal * rate * time) / 100;
}

// Inputs: principal=1000, rate=5, time=2
A100
B50
C200
D10
Attempts:
2 left
💡 Hint
Remember simple interest formula: (P * R * T) / 100
🧠 Conceptual
intermediate
1:30remaining
Which feature of DeFi removes the need for traditional banks?
DeFi uses blockchain technology to replace traditional financial intermediaries. Which feature best explains this?
ACentralized control by a single authority
BSmart contracts that automate trustless transactions
CManual verification by trusted third parties
DPhysical branches for customer service
Attempts:
2 left
💡 Hint
Think about how trust is managed without banks.
🔧 Debug
advanced
2:30remaining
What error does this Solidity code produce when deploying a DeFi token?
This Solidity snippet tries to create a token but has a bug. What error will the compiler show?
Blockchain / Solidity
contract Token {
    string public name = "DeFiToken";
    uint public totalSupply = 1000;
    mapping(address => uint) balances;

    constructor() public {
        balances[msg.sender] = totalSupply;
    }
}
ATypeError: Constructor must be declared 'constructor' in Solidity >=0.7.0
BSyntaxError: Missing semicolon after balances declaration
CRuntimeError: Division by zero
DNo error, compiles successfully
Attempts:
2 left
💡 Hint
Check how constructors are declared in recent Solidity versions.
📝 Syntax
advanced
2:00remaining
Which JavaScript snippet correctly interacts with a DeFi smart contract using ethers.js?
You want to call the 'balanceOf' function on a DeFi token contract. Which code snippet is correct?
Blockchain / Solidity
const contractAddress = '0x123...';
const abi = ["function balanceOf(address) view returns (uint)"];
const provider = new ethers.providers.JsonRpcProvider();
const contract = new ethers.Contract(contractAddress, abi, provider);
const address = '0xabc...';
Aconst balance = contract.balanceOf(address).toString(); console.log(balance);
Bconst balance = contract.balanceOf(address); console.log(balance);
Cconst balance = await contract.balanceOf; console.log(balance);
Dconst balance = await contract.balanceOf(address); console.log(balance.toString());
Attempts:
2 left
💡 Hint
Remember that contract calls returning promises need 'await'.
🚀 Application
expert
3:00remaining
How many unique liquidity pools are created by this Uniswap-like pair factory code?
Given this simplified factory code snippet that creates liquidity pools for token pairs, how many unique pools exist after these calls? factory.createPair('TokenA', 'TokenB'); factory.createPair('TokenB', 'TokenA'); factory.createPair('TokenA', 'TokenC'); factory.createPair('TokenC', 'TokenA'); factory.createPair('TokenB', 'TokenC');
Blockchain / Solidity
class Factory {
  constructor() {
    this.pairs = new Set();
  }
  createPair(token1, token2) {
    const sorted = [token1, token2].sort();
    const key = sorted.join('-');
    this.pairs.add(key);
  }
  getPairCount() {
    return this.pairs.size;
  }
}

const factory = new Factory();
factory.createPair('TokenA', 'TokenB');
factory.createPair('TokenB', 'TokenA');
factory.createPair('TokenA', 'TokenC');
factory.createPair('TokenC', 'TokenA');
factory.createPair('TokenB', 'TokenC');

const count = factory.getPairCount();
A4
B5
C3
D2
Attempts:
2 left
💡 Hint
Pairs with tokens in different order count as the same pool.

Practice

(1/5)
1. What is one main way DeFi changes traditional finance?
easy
A. By removing banks and middlemen
B. By requiring physical bank branches
C. By using paper money only
D. By limiting access to certain countries

Solution

  1. Step 1: Understand DeFi's core feature

    DeFi uses technology to remove banks and middlemen from financial processes.
  2. Step 2: Compare options to this feature

    Only By removing banks and middlemen matches this key idea; others contradict it.
  3. Final Answer:

    By removing banks and middlemen -> Option A
  4. Quick Check:

    DeFi removes middlemen = C [OK]
Hint: Think about who controls money in DeFi [OK]
Common Mistakes:
  • Thinking DeFi needs physical banks
  • Assuming DeFi limits users by location
  • Confusing DeFi with cash-only systems
2. Which of the following is the correct way to describe a DeFi smart contract?
easy
A. A paper document stored in a vault
B. A physical contract signed by banks
C. A self-executing code on blockchain
D. A manual process requiring human approval

Solution

  1. Step 1: Define smart contract in DeFi

    Smart contracts are computer programs that run automatically on blockchain.
  2. Step 2: Match options to this definition

    Only self-executing code on blockchain matches this definition.
  3. Final Answer:

    A self-executing code on blockchain -> Option C
  4. Quick Check:

    Smart contract = code on blockchain [OK]
Hint: Smart contracts run automatically, no paper needed [OK]
Common Mistakes:
  • Thinking smart contracts are physical papers
  • Confusing manual approval with automation
  • Assuming banks sign smart contracts
3. Consider this simple DeFi smart contract code snippet in Solidity:
contract SimpleBank {
    mapping(address => uint) balances;
    function deposit() public payable {
        balances[msg.sender] += msg.value;
    }
    function getBalance() public view returns (uint) {
        return balances[msg.sender];
    }
}

What will getBalance() return after a user sends 2 ether to deposit()?
medium
A. 2 ether in wei units
B. 2
C. Error: function not payable
D. 0

Solution

  1. Step 1: Understand deposit function behavior

    The deposit function adds the sent ether (msg.value) to the sender's balance in wei (smallest ether unit).
  2. Step 2: Understand getBalance return value

    getBalance returns the balance in wei, so sending 2 ether means balance is 2 * 10^18 wei.
  3. Final Answer:

    2 ether in wei units -> Option A
  4. Quick Check:

    Balance returned in wei units = D [OK]
Hint: Ether amounts are stored in wei (smallest unit) [OK]
Common Mistakes:
  • Assuming balance returns ether directly
  • Thinking deposit is not payable
  • Confusing zero balance with deposit amount
4. This Solidity code snippet aims to let users withdraw their balance:
contract SimpleBank {
    mapping(address => uint) balances;
    function withdraw(uint amount) public {
        require(balances[msg.sender] >= amount);
        payable(msg.sender).transfer(amount);
        balances[msg.sender] -= amount;
    }
}

What is the main issue with this code?
medium
A. It does not check if amount is positive
B. It subtracts balance after transfer, risking reentrancy attack
C. It uses transfer instead of send
D. It lacks a deposit function

Solution

  1. Step 1: Analyze withdrawal order

    The code sends ether before updating the balance, which can allow reentrancy attacks.
  2. Step 2: Identify security best practice

    Best practice is to update balance before sending ether to prevent reentrancy.
  3. Final Answer:

    It subtracts balance after transfer, risking reentrancy attack -> Option B
  4. Quick Check:

    Transfer before update risks reentrancy = B [OK]
Hint: Update balance before sending funds to avoid attacks [OK]
Common Mistakes:
  • Ignoring reentrancy risks
  • Thinking transfer vs send is main issue
  • Missing importance of deposit function here
5. You want to create a DeFi app that lets users stake tokens and earn rewards automatically. Which combination best reimagines finance using DeFi principles?
hard
A. Limit staking to only users with bank accounts
B. Require users to visit a bank to approve staking manually
C. Use paper contracts signed by a central authority
D. Use smart contracts to automate staking and rewards without intermediaries

Solution

  1. Step 1: Identify DeFi principles

    DeFi automates finance tasks with smart contracts and removes middlemen.
  2. Step 2: Match options to these principles

    Only the option using smart contracts to automate without intermediaries matches.
  3. Final Answer:

    Use smart contracts to automate staking and rewards without intermediaries -> Option D
  4. Quick Check:

    Automation + no middlemen = A [OK]
Hint: Choose automation and no middlemen for DeFi apps [OK]
Common Mistakes:
  • Thinking manual bank visits fit DeFi
  • Assuming paper contracts are needed
  • Limiting access contradicts DeFi openness