0
0
Blockchain / Solidityprogramming~20 mins

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

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