0
0
Blockchain / Solidityprogramming~10 mins

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

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

Complete the code to define a smart contract function that returns the contract's owner address.

Blockchain / Solidity
function getOwner() public view returns (address) {
    return [1];
}
Drag options to blanks, or click blank then click option'
Aowner
Bmsg.sender
Caddress(this)
Dtx.origin
Attempts:
3 left
💡 Hint
Common Mistakes
Returning msg.sender instead of owner
Returning address(this) which is the contract address
2fill in blank
medium

Complete the code to emit an event when a token transfer happens.

Blockchain / Solidity
emit Transfer([1], to, amount);
Drag options to blanks, or click blank then click option'
Afrom
Bowner
Cmsg.sender
Drecipient
Attempts:
3 left
💡 Hint
Common Mistakes
Using recipient or to instead of from
Using msg.sender which may differ from from in some cases
3fill in blank
hard

Fix the error in the function that checks if the caller is the owner.

Blockchain / Solidity
require([1] == owner, "Not authorized");
Drag options to blanks, or click blank then click option'
Atx.origin
Bowner
Cmsg.sender
Daddress(this)
Attempts:
3 left
💡 Hint
Common Mistakes
Using tx.origin which can be spoofed
Using address(this) which is the contract address
4fill in blank
hard

Fill both blanks to create a mapping that tracks balances and a function to update them.

Blockchain / Solidity
mapping(address => [1]) public balances;

function updateBalance(address user, [2] amount) public {
    balances[user] = amount;
}
Drag options to blanks, or click blank then click option'
Auint256
Baddress
Cuint
Dbool
Attempts:
3 left
💡 Hint
Common Mistakes
Using bool instead of number
Using address as balance type
5fill in blank
hard

Fill all three blanks to create a function that transfers tokens safely.

Blockchain / Solidity
function safeTransfer(address [1], address [2], uint [3]) public {
    require(balances[[1]] >= [3], "Insufficient balance");
    balances[[1]] -= [3];
    balances[[2]] += [3];
}
Drag options to blanks, or click blank then click option'
Afrom
Bto
Camount
Duser
Attempts:
3 left
💡 Hint
Common Mistakes
Using user instead of from or to
Mixing parameter order