0
0
Blockchain / Solidityprogramming~10 mins

Staking mechanisms in Blockchain / Solidity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare a staking balance mapping in Solidity.

Blockchain / Solidity
mapping(address => uint256) public [1];
Drag options to blanks, or click blank then click option'
AstakeAmount
BstakingBalance
Cbalances
DuserStake
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not clearly represent staking balances.
Forgetting to specify the mapping key or value types.
2fill in blank
medium

Complete the code to allow users to stake tokens by updating their balance.

Blockchain / Solidity
function stakeTokens(uint256 _amount) public {
    require(_amount > 0, "Amount must be greater than zero");
    [1][msg.sender] += _amount;
}
Drag options to blanks, or click blank then click option'
AstakingBalance
Bbalances
CuserStake
DstakeAmount
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong mapping name.
Not using msg.sender as the key.
3fill in blank
hard

Fix the error in the function that allows users to unstake their tokens.

Blockchain / Solidity
function unstakeTokens() public {
    uint256 balance = [1][msg.sender];
    require(balance > 0, "No tokens to unstake");
    stakingBalance[msg.sender] = 0;
    // Transfer tokens back to user
}
Drag options to blanks, or click blank then click option'
AstakingBalance
BuserStake
Cbalances
DstakeAmount
Attempts:
3 left
💡 Hint
Common Mistakes
Using a mapping name that does not exist or is inconsistent.
Not checking the correct balance before unstaking.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps user addresses to their staked amounts greater than zero.

Blockchain / Solidity
activeStakes = {address: amount for (address, amount) in [1].items() if amount [2] 0};
Drag options to blanks, or click blank then click option'
AstakingBalance
B>
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator.
Using a mapping name that does not exist.
5fill in blank
hard

Fill all three blanks to calculate rewards for each user with staked tokens above a threshold.

Blockchain / Solidity
rewards = { [1]: [2] * rewardRate for ([3], amount) in stakingBalance.items() if amount > threshold };
Drag options to blanks, or click blank then click option'
Auser
Bamount
Dstake
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up variable names in the comprehension.
Using incorrect variable names for keys or values.