0
0
Blockchain / Solidityprogramming~20 mins

Smart contract concept in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Smart Contract 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 call?

Consider this Solidity smart contract snippet:

pragma solidity ^0.8.0;

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

If we call set(42) and then get(), what will get() return?

Blockchain / Solidity
pragma solidity ^0.8.0;

contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}
ATransaction revert error
B42
CCompilation error
D0
Attempts:
2 left
💡 Hint

Think about what the set function does before calling get.

🧠 Conceptual
intermediate
1:30remaining
Which statement best describes a smart contract?

Choose the best description of a smart contract in blockchain technology.

AA centralized database storing user information securely.
BA legal contract signed digitally between two parties.
CA self-executing program that runs on a blockchain and enforces rules automatically.
DA cryptocurrency wallet used to store tokens.
Attempts:
2 left
💡 Hint

Think about what makes smart contracts different from traditional contracts.

🔧 Debug
advanced
2:00remaining
What error does this Solidity code produce?

Examine this Solidity function:

function divide(uint a, uint b) public pure returns (uint) {
    return a / b;
}

What happens if b is zero when calling divide(10, 0)?

Blockchain / Solidity
function divide(uint a, uint b) public pure returns (uint) {
    return a / b;
}
AThrows a division by zero runtime error and reverts the transaction
BCompiles with a warning but runs normally
CReturns 0
DReturns a large number due to overflow
Attempts:
2 left
💡 Hint

What happens in programming when you divide by zero?

📝 Syntax
advanced
1:30remaining
Which option correctly declares a payable function in Solidity?

In Solidity, which function declaration allows the function to receive Ether?

Afunction deposit() public payable {}
Bfunction deposit() public pay {}
Cfunction deposit() public payable returns (uint) {}
Dfunction deposit() public payable() {}
Attempts:
2 left
💡 Hint

Look for the correct keyword and syntax for payable functions.

🚀 Application
expert
2:30remaining
How many items are in the mapping after this transaction?

Given this Solidity contract snippet:

contract Registry {
    mapping(address => bool) public registered;

    function register() public {
        registered[msg.sender] = true;
    }
}

If three different users call register() once each, how many entries will registered contain?

A1
BCannot be determined
C0
D3
Attempts:
2 left
💡 Hint

Think about how mappings store data for unique keys.