Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does deploying a smart contract mean in blockchain?
easy
A. Testing the contract on a local computer only
B. Making the contract code live and usable on the blockchain
C. Writing the contract code in a text editor
D. Deleting the contract from the blockchain

Solution

  1. Step 1: Understand deployment meaning

    Deployment means putting the contract code on the blockchain so it can run.
  2. Step 2: Differentiate from writing and testing

    Writing is coding, testing is checking locally or on test networks, deployment is live on blockchain.
  3. Final Answer:

    Making the contract code live and usable on the blockchain -> Option B
  4. Quick Check:

    Deploy = live on blockchain [OK]
Hint: Deployment means contract is live on blockchain [OK]
Common Mistakes:
  • Confusing deployment with just writing code
  • Thinking testing is deployment
  • Believing deployment deletes contracts
2. Which of the following is the correct Solidity syntax to start a simple contract named MyContract?
easy
A. contract MyContract { }
B. class MyContract { }
C. function MyContract() { }
D. contract = MyContract()

Solution

  1. Step 1: Recall Solidity contract declaration

    Solidity uses the keyword contract followed by the contract name and braces.
  2. Step 2: Check each option's syntax

    contract MyContract { } matches Solidity syntax; others use wrong keywords or formats.
  3. Final Answer:

    contract MyContract { } -> Option A
  4. Quick Check:

    Solidity contract starts with 'contract' keyword [OK]
Hint: Solidity contracts start with 'contract' keyword [OK]
Common Mistakes:
  • Using 'class' instead of 'contract'
  • Writing function instead of contract
  • Assigning contract like a variable
3. Given this Solidity contract snippet deployed on a test network:
contract Counter {
  uint count = 0;
  function increment() public {
    count += 1;
  }
  function getCount() public view returns (uint) {
    return count;
  }
}

If you call increment() twice and then getCount(), what is the output?
medium
A. 0
B. 1
C. 2
D. Error: function not found

Solution

  1. Step 1: Understand contract state changes

    Each call to increment() adds 1 to count, starting from 0.
  2. Step 2: Calculate after two increments

    After two calls, count becomes 2. getCount() returns this value.
  3. Final Answer:

    2 -> Option C
  4. Quick Check:

    2 increments = count 2 [OK]
Hint: Each increment adds 1; two increments mean count is 2 [OK]
Common Mistakes:
  • Forgetting state changes persist on blockchain
  • Assuming count resets each call
  • Confusing function names
4. You try to deploy this Solidity contract but get a syntax error:
contract Simple {
  uint number
  function setNumber(uint num) public {
    number = num;
  }
}

What is the cause of the error?
medium
A. Missing return type in function
B. Function setNumber must be private
C. Contract name must be lowercase
D. Missing semicolon after uint number

Solution

  1. Step 1: Check Solidity syntax rules

    Variable declarations require a semicolon at the end.
  2. Step 2: Identify missing semicolon

    uint number line misses a semicolon, causing syntax error.
  3. Final Answer:

    Missing semicolon after uint number -> Option D
  4. Quick Check:

    Missing semicolon = syntax error [OK]
Hint: Check semicolons after variable declarations [OK]
Common Mistakes:
  • Thinking function visibility causes syntax error
  • Believing contract names must be lowercase
  • Expecting return type for void functions
5. You want to deploy a smart contract that stores user names and their balances. Which approach is best to deploy and test it safely before using real money?
hard
A. Deploy on a test network like Ropsten or Goerli first
B. Deploy directly on the main Ethereum network
C. Write the contract but never deploy it
D. Deploy on a private computer without blockchain

Solution

  1. Step 1: Understand deployment environments

    Mainnet uses real money; testnets simulate blockchain without real cost.
  2. Step 2: Choose safe testing method

    Deploying on testnets like Ropsten or Goerli lets you test without risking real funds.
  3. Final Answer:

    Deploy on a test network like Ropsten or Goerli first -> Option A
  4. Quick Check:

    Testnet deployment = safe testing [OK]
Hint: Use test networks to avoid losing real money [OK]
Common Mistakes:
  • Deploying directly on mainnet without testing
  • Not deploying at all and missing testing
  • Using private computer without blockchain for deployment
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard