0
0
Blockchain / Solidityprogramming~20 mins

Balance checking in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Balance 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 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 wei
A0
B3
C3000000000000000
D3000000000000000000
Attempts:
2 left
💡 Hint
Remember that balances are returned in wei, the smallest unit.
Predict Output
intermediate
2: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?
ARuntime error: invalid address
BCompilation error: uninitialized address
CReturns 0
DReturns random value
Attempts:
2 left
💡 Hint
Default value of address type is zero address.
Predict Output
advanced
2: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);
A"5"
B"5000000000000000000"
C5
Dundefined
Attempts:
2 left
💡 Hint
fromWei returns a string representation.
🧠 Conceptual
advanced
2: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?
ABecause balance is a state variable stored in contract storage
BBecause balance is a global property accessed via EVM opcode that does not modify state
CBecause balance is cached locally in the contract
DBecause balance is computed by the contract at runtime
Attempts:
2 left
💡 Hint
Think about what operations cost gas in Ethereum.
Predict Output
expert
2: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?
A100000000000000000
B0.1
C0
DCompilation error
Attempts:
2 left
💡 Hint
Balance is returned in wei, not ether.