Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

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

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

Practice

(1/5)
1.

What does balance checking in blockchain primarily tell you?

easy
A. The private key of a wallet
B. The transaction history of an address
C. How much cryptocurrency an address currently holds
D. The mining difficulty of the blockchain

Solution

  1. Step 1: Understand the purpose of balance checking

    Balance checking is used to find out the amount of cryptocurrency held by a blockchain address.
  2. Step 2: Differentiate from other blockchain data

    Transaction history, private keys, and mining difficulty are different concepts unrelated to balance checking.
  3. Final Answer:

    How much cryptocurrency an address currently holds -> Option C
  4. Quick Check:

    Balance checking = cryptocurrency amount [OK]
Hint: Balance checking shows funds held by an address [OK]
Common Mistakes:
  • Confusing balance with transaction history
  • Thinking balance reveals private keys
  • Mixing balance with blockchain mining info
2.

Which of the following is the correct way to call a function getBalance for an address addr in a blockchain library?

?
easy
A. getBalance(addr)
B. getBalance = addr
C. getBalance.addr()
D. getBalance->addr()

Solution

  1. Step 1: Identify correct function call syntax

    In most programming languages, calling a function with an argument uses parentheses: functionName(argument).
  2. Step 2: Check each option

    getBalance(addr) uses correct syntax: getBalance(addr). Options A, C, and D use invalid or incorrect syntax.
  3. Final Answer:

    getBalance(addr) -> Option A
  4. Quick Check:

    Function call syntax = getBalance(addr) [OK]
Hint: Function calls use parentheses with arguments [OK]
Common Mistakes:
  • Using assignment instead of function call
  • Using dot notation incorrectly for function calls
  • Using arrow notation which is not valid here
3.

Given this JavaScript code snippet using a blockchain API:

async function check() {
  const balance = await blockchainAPI.getBalance('0x123');
  console.log(balance);
}
check();

What will be printed if the address has 500 tokens?

medium
A. undefined
B. 500
C. Error: getBalance is not a function
D. null

Solution

  1. Step 1: Understand async/await usage

    The function uses await to get the balance asynchronously, so balance will hold the returned value.
  2. Step 2: Check what is logged

    console.log(balance) will print the balance value, which is 500 tokens for the given address.
  3. Final Answer:

    500 -> Option B
  4. Quick Check:

    Async balance fetch = 500 [OK]
Hint: Await returns the actual balance value [OK]
Common Mistakes:
  • Ignoring async and expecting immediate value
  • Assuming undefined if await is missing
  • Confusing error messages with correct output
4.

Find the error in this Python code that tries to get a balance:

def get_balance(address):
    balance = blockchain.getBalance(address)
    return balance

print(get_balance)
medium
A. Using print instead of return
B. Incorrect function name getBalance
C. Missing import statement for blockchain
D. Missing parentheses when calling get_balance in print

Solution

  1. Step 1: Check how get_balance is used in print

    The code prints get_balance without parentheses, so it prints the function object, not the result.
  2. Step 2: Correct usage to call the function

    Adding parentheses and an argument like print(get_balance('0xabc')) calls the function and prints the balance.
  3. Final Answer:

    Missing parentheses when calling get_balance in print -> Option D
  4. Quick Check:

    Function call needs () [OK]
Hint: Call functions with () to get results [OK]
Common Mistakes:
  • Printing function name instead of calling it
  • Assuming function runs without parentheses
  • Ignoring required function arguments
5.

You want to check balances of multiple addresses and store them in a dictionary in Python. Which code correctly does this?

addresses = ['0x1', '0x2', '0x3']
balances = {}
for addr in addresses:
    balances[addr] = blockchain.getBalance(addr)
print(balances)
hard
A. This code correctly stores balances for each address in a dictionary
B. This code will cause a syntax error due to missing colon
C. This code overwrites balances instead of storing all
D. This code does not call getBalance correctly

Solution

  1. Step 1: Analyze the loop and dictionary usage

    The for loop iterates over each address and assigns the balance to balances[addr], storing all balances.
  2. Step 2: Check syntax and function call

    Syntax is correct with colon and indentation; getBalance is called properly with each address.
  3. Final Answer:

    This code correctly stores balances for each address in a dictionary -> Option A
  4. Quick Check:

    Loop + dict assignment = correct balances [OK]
Hint: Use a loop to assign balances to dictionary keys [OK]
Common Mistakes:
  • Forgetting colon after for statement
  • Overwriting dictionary instead of adding keys
  • Calling getBalance without argument
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