Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

Accounts (EOA vs contract accounts) in Blockchain / Solidity - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Master of Accounts (EOA vs contract accounts)
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 code snippet?
Consider the following Solidity code that checks if an address is a contract or an externally owned account (EOA). What will be the output when calling checkAccountType with an EOA address?
Blockchain / Solidity
pragma solidity ^0.8.0;

contract AccountChecker {
    function isContract(address account) public view returns (bool) {
        uint32 size;
        assembly {
            size := extcodesize(account)
        }
        return (size > 0);
    }

    function checkAccountType(address account) public view returns (string memory) {
        if (isContract(account)) {
            return "Contract Account";
        } else {
            return "Externally Owned Account";
        }
    }
}
A"Externally Owned Account"
BRuntime error due to extcodesize usage
CCompilation error due to assembly block
D"Contract Account"
Attempts:
2 left
💡 Hint
Remember that EOAs have no code, so extcodesize returns zero for them.
🧠 Conceptual
intermediate
1:30remaining
Which statement correctly describes EOAs and contract accounts?
Select the statement that accurately distinguishes between externally owned accounts (EOAs) and contract accounts in Ethereum.
ABoth EOAs and contract accounts have private keys controlling them.
BEOAs have associated code and can execute functions, while contract accounts cannot.
CContract accounts have associated code and can execute functions, while EOAs are controlled by private keys and have no code.
DContract accounts are controlled by users via private keys, EOAs are controlled by smart contracts.
Attempts:
2 left
💡 Hint
Think about who controls EOAs and what code means for contract accounts.
🔧 Debug
advanced
2:30remaining
Why does this Solidity function always return false for contract addresses?
This Solidity function is intended to detect if an address is a contract. However, it always returns false even for contract addresses. Identify the reason.
Blockchain / Solidity
function isContract(address account) public view returns (bool) {
    uint size;
    assembly {
        size := extcodesize(account)
    }
    return (size == 0);
}
AThe assembly block syntax is invalid, causing the function to always return false.
BThe function incorrectly returns true when size is zero, so it returns false for contracts.
CThe variable 'size' is not initialized, causing unpredictable results.
DThe function should use extcodehash instead of extcodesize to detect contracts.
Attempts:
2 left
💡 Hint
Check the return condition comparing size to zero.
📝 Syntax
advanced
2:30remaining
Which option correctly compiles and returns the number of contract accounts in an array?
Given an array of addresses, which code snippet correctly counts how many are contract accounts using extcodesize?
Blockchain / Solidity
address[] memory accounts = new address[](3);
accounts[0] = 0x123...;
accounts[1] = 0x456...;
accounts[2] = 0x789...;

uint count = 0;
// Count contract accounts here
A
for (uint i = 0; i < accounts.length; i++) {
    uint size;
    assembly { size := extcodesize(accounts[i]) }
    if (size > 0) {
        count += 1;
    }
}
B
for (uint i = 0; i < accounts.length; i++) {
    uint size = extcodesize(accounts[i]);
    if (size > 0) {
        count++;
    }
}
C
for (uint i = 0; i < accounts.length; i++) {
    uint size;
    assembly { size := extcodesize(accounts[i]) }
    if (size == 0) {
        count += 1;
    }
}
D
for (uint i = 0; i < accounts.length; i++) {
    uint size;
    assembly { size := extcodesize(accounts[i]) }
    if (size > 0) {
        count = count + 1
    }
}
Attempts:
2 left
💡 Hint
Remember to use assembly correctly and check for size > 0.
🚀 Application
expert
3:00remaining
What is the value of result after executing this Solidity code?
Given the following Solidity contract, what is the value of result after calling test()?
Blockchain / Solidity
pragma solidity ^0.8.0;

contract TestContract {
    address public eoa;
    address public contractAddr;

    constructor(address _eoa, address _contractAddr) {
        eoa = _eoa;
        contractAddr = _contractAddr;
    }

    function isContract(address account) internal view returns (bool) {
        uint size;
        assembly { size := extcodesize(account) }
        return size > 0;
    }

    function test() public view returns (string memory result) {
        if (isContract(eoa) && isContract(contractAddr)) {
            result = "Both are contracts";
        } else if (isContract(eoa)) {
            result = "EOA is contract";
        } else if (isContract(contractAddr)) {
            result = "Contract address is contract";
        } else {
            result = "Neither is contract";
        }
    }
}
A"Both are contracts"
B"Neither is contract"
C"EOA is contract"
D"Contract address is contract"
Attempts:
2 left
💡 Hint
EOAs have no code, contract addresses do.

Practice

(1/5)
1. Which of the following best describes an Externally Owned Account (EOA) on a blockchain?
easy
A. An account that can only receive tokens but not send them.
B. An account that only stores data but cannot send transactions.
C. An account that automatically executes code when called.
D. An account controlled by a private key, used by people to send transactions.

Solution

  1. Step 1: Understand what an EOA is

    An EOA is controlled by a private key and represents a user or person on the blockchain.
  2. Step 2: Identify EOA capabilities

    EOAs can send transactions and initiate actions, unlike contract accounts which run code.
  3. Final Answer:

    An account controlled by a private key, used by people to send transactions. -> Option D
  4. Quick Check:

    EOA = user-controlled account [OK]
Hint: EOAs are user accounts with private keys [OK]
Common Mistakes:
  • Confusing EOAs with contract accounts
  • Thinking EOAs run code automatically
  • Believing EOAs cannot send transactions
2. Which syntax correctly represents a contract account address in Solidity?
easy
A. address payable contractAddr = 0x1234567890abcdef1234567890abcdef12345678;
B. contractAddr = '0x1234567890abcdef1234567890abcdef12345678';
C. address contractAddr = 1234567890abcdef1234567890abcdef12345678;
D. address contractAddr = 0xGHIJKL7890abcdef1234567890abcdef12345678;

Solution

  1. Step 1: Check Solidity address syntax

    Addresses must be hexadecimal starting with 0x and enclosed in proper type declaration.
  2. Step 2: Validate each option

    The declaration 'address payable contractAddr = 0x1234567890abcdef1234567890abcdef12345678;' uses correct type and hex format. String assignments without type declaration are invalid, missing 0x prefix fails, and invalid hex characters like 'GHI' are not allowed.
  3. Final Answer:

    address payable contractAddr = 0x1234567890abcdef1234567890abcdef12345678; -> Option A
  4. Quick Check:

    Valid Solidity address syntax = address payable contractAddr = 0x1234567890abcdef1234567890abcdef12345678; [OK]
Hint: Solidity addresses start with 0x and use 'address' type [OK]
Common Mistakes:
  • Omitting 0x prefix
  • Using invalid hex characters
  • Assigning address as a plain string without type
3. Consider the following Solidity code snippet:
address sender = msg.sender;
bool isContract = sender.code.length > 0;

What does isContract indicate?
medium
A. True if sender is an EOA, false if contract.
B. True if sender is a contract account, false if EOA.
C. Always true because msg.sender is a contract.
D. Always false because msg.sender has no code.

Solution

  1. Step 1: Understand msg.sender.code.length

    This checks the length of the code at the sender's address; contracts have code, EOAs do not.
  2. Step 2: Interpret the boolean value

    If code length > 0, sender is a contract account; otherwise, it's an EOA.
  3. Final Answer:

    True if sender is a contract account, false if EOA. -> Option B
  4. Quick Check:

    Code length > 0 means contract [OK]
Hint: Check code length to distinguish contract vs EOA [OK]
Common Mistakes:
  • Assuming msg.sender is always EOA
  • Confusing code length meaning
  • Thinking EOAs have code
4. You have this Solidity function:
function sendEther(address recipient) public {
    recipient.transfer(1 ether);
}

When calling this function with an EOA address, it fails with an error. What is the likely cause?
medium
A. The recipient address is not payable, so transfer fails.
B. EOA addresses cannot receive ether.
C. The function lacks the payable modifier.
D. transfer() only works with contract accounts.

Solution

  1. Step 1: Understand transfer() requirements

    transfer() requires the recipient address to be payable to receive ether.
  2. Step 2: Analyze recipient type

    If recipient is declared as address (not address payable), transfer will fail even if it's an EOA.
  3. Final Answer:

    The recipient address is not payable, so transfer fails. -> Option A
  4. Quick Check:

    Use address payable for ether transfers [OK]
Hint: Use address payable to send ether [OK]
Common Mistakes:
  • Thinking EOAs can't receive ether
  • Missing payable keyword on function
  • Assuming transfer only works with contracts
5. You want to write a Solidity function that sends 1 ether only if the recipient is an EOA (not a contract). Which code snippet correctly implements this check?
hard
A. require(recipient.balance > 0, "Recipient must have balance"); recipient.transfer(1 ether);
B. require(recipient.code.length > 0, "Recipient must be contract"); payable(recipient).transfer(1 ether);
C. require(recipient.code.length == 0, "Recipient must be EOA"); payable(recipient).transfer(1 ether);
D. require(msg.sender == recipient, "Sender must be recipient"); recipient.transfer(1 ether);

Solution

  1. Step 1: Check recipient code length to identify EOA

    EOAs have no code, so recipient.code.length == 0 confirms EOA.
  2. Step 2: Use require to enforce condition and transfer ether

    If recipient is EOA, convert to payable and transfer 1 ether safely.
  3. Final Answer:

    require(recipient.code.length == 0, "Recipient must be EOA"); payable(recipient).transfer(1 ether); -> Option C
  4. Quick Check:

    Code length 0 means EOA, then transfer [OK]
Hint: Check code length == 0 to confirm EOA before sending [OK]
Common Mistakes:
  • Checking for code length > 0 to find EOAs
  • Not converting address to payable before transfer
  • Using balance check instead of code length
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