0
0
Blockchain / Solidityprogramming~20 mins

First smart contract deployment in Blockchain / Solidity - Practice Problems & Coding Challenges

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

Consider this simple smart contract that emits an event when deployed. What will be the value of the event's message when the contract is deployed?

Blockchain / Solidity
pragma solidity ^0.8.0;

contract HelloWorld {
    event Greet(string message);

    constructor() {
        emit Greet("Hello, Blockchain!");
    }
}
A"Hello, World!"
BNo event emitted
C"Hello, Blockchain!"
DCompilation error
Attempts:
2 left
💡 Hint

Look at the string inside the emit Greet(...) statement in the constructor.

Predict Output
intermediate
2:00remaining
What is the value of the stored variable after deployment?

This contract stores a number passed during deployment. What will be the value of storedNumber after deployment with the argument 42?

Blockchain / Solidity
pragma solidity ^0.8.0;

contract StoreNumber {
    uint public storedNumber;

    constructor(uint _num) {
        storedNumber = _num;
    }
}
A42
B0
CCompilation error
DUndefined
Attempts:
2 left
💡 Hint

The constructor sets storedNumber to the input parameter _num.

🔧 Debug
advanced
2:00remaining
Why does this contract deployment fail?

Examine the contract below. When trying to deploy it, the deployment fails with a compilation error. What is the cause?

Blockchain / Solidity
pragma solidity ^0.8.0;

contract Counter {
    uint count;

    constructor() {
        count = 0;
    }
}
ACannot assign zero to uint
BMissing semicolon after <code>count = 0</code>
CConstructor must have a visibility modifier
DState variable <code>count</code> must be public
Attempts:
2 left
💡 Hint

Check the syntax of the assignment line inside the constructor.

🧠 Conceptual
advanced
2:00remaining
Which statement about smart contract deployment is true?

Choose the correct statement about deploying a smart contract on Ethereum.

ADeployment stores the contract code and runs the constructor once
BDeployment runs the contract functions repeatedly until stopped
CDeployment requires no gas fees
DDeployment automatically grants admin rights to all users
Attempts:
2 left
💡 Hint

Think about what happens exactly once during deployment.

Predict Output
expert
3:00remaining
What is the output of this deployment and function call sequence?

Given this contract, what will be the output of calling getMessage() immediately after deployment?

Blockchain / Solidity
pragma solidity ^0.8.0;

contract Message {
    string private message;

    constructor() {
        setMessage("Welcome!");
    }

    function setMessage(string memory _msg) public {
        message = _msg;
    }

    function getMessage() public view returns (string memory) {
        return message;
    }
}
ARuntime error
B"" (empty string)
CCompilation error due to calling public function in constructor
D"Welcome!"
Attempts:
2 left
💡 Hint

The constructor calls setMessage with "Welcome!" before deployment finishes.