0
0
Blockchain / Solidityprogramming~20 mins

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

Choose your learning style9 modes available
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.