Challenge - 5 Problems
Balance Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this Ethereum balance check?
Given the following Solidity function that returns the balance of an address in wei, what will be the output if the address has 3 ether?
Blockchain / Solidity
function getBalance(address addr) public view returns (uint) {
return addr.balance;
}
// Assume 1 ether = 10**18 weiAttempts:
2 left
💡 Hint
Remember that balances are returned in wei, the smallest unit.
✗ Incorrect
The balance property returns the amount in wei. Since 1 ether = 10^18 wei, 3 ether = 3 * 10^18 wei = 3000000000000000000 wei.
❓ Predict Output
intermediate2:00remaining
What error occurs when checking balance of an uninitialized address?
Consider this Solidity snippet:
address addr;
uint bal = addr.balance;
What happens when this code runs?
Attempts:
2 left
💡 Hint
Default value of address type is zero address.
✗ Incorrect
Uninitialized address variables default to the zero address (0x000...0), which has zero balance, so it returns 0.
❓ Predict Output
advanced2:00remaining
What is the output of this Web3.js balance check?
Given this JavaScript code using Web3.js to get balance in ether, what is logged if the account has 5 ether?
const balanceWei = await web3.eth.getBalance(account);
const balanceEth = web3.utils.fromWei(balanceWei, 'ether');
console.log(balanceEth);
Attempts:
2 left
💡 Hint
fromWei returns a string representation.
✗ Incorrect
fromWei converts wei to ether and returns a string, so console.log prints "5" as a string.
🧠 Conceptual
advanced2:00remaining
Which option correctly explains why balance checking is gas-free in Solidity?
Why does reading the balance of an address using addr.balance not consume gas in Solidity?
Attempts:
2 left
💡 Hint
Think about what operations cost gas in Ethereum.
✗ Incorrect
Reading balance uses the EVM BALANCE opcode which only reads state and does not modify it, so it costs no gas when called externally.
❓ Predict Output
expert2:00remaining
What is the value of 'balance' after this Solidity code runs?
Consider this Solidity code snippet:
address payable user = payable(address(0x123));
uint balance = user.balance;
Assuming the address 0x123 has 0.1 ether, what is the value of balance?
Attempts:
2 left
💡 Hint
Balance is returned in wei, not ether.
✗ Incorrect
The balance property returns the amount in wei. 0.1 ether equals 0.1 * 10^18 = 100000000000000000 wei.