0
0
Blockchain / Solidityprogramming~20 mins

Batch operations in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Batch Operations 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 batch transaction simulation?

Consider a batch operation that sends 3 transactions in sequence. Each transaction adds 10 to a shared counter starting at 0. What is the final counter value after all transactions succeed?

Blockchain / Solidity
let counter = 0;
const batch = [
  () => { counter += 10; return counter; },
  () => { counter += 10; return counter; },
  () => { counter += 10; return counter; }
];
for (const tx of batch) {
  tx();
}
console.log(counter);
AError: counter is undefined
B30
C10
D0
Attempts:
2 left
💡 Hint

Each transaction adds 10 to the counter. Think about how many times this happens.

🧠 Conceptual
intermediate
1:30remaining
Which statement best describes batch operations in blockchain?

Choose the correct description of batch operations in blockchain systems.

ABatch operations execute multiple transactions atomically in one block to save gas and ensure all succeed or fail together.
BBatch operations split a single transaction into multiple smaller transactions to increase fees.
CBatch operations delay transactions indefinitely until network congestion clears.
DBatch operations are only used to mine new blocks faster.
Attempts:
2 left
💡 Hint

Think about why batching transactions is useful for cost and consistency.

🔧 Debug
advanced
2:30remaining
Why does this batch transaction fail to update all balances?

Given the following Solidity batch transfer function, why does only the first transfer succeed?

Blockchain / Solidity
function batchTransfer(address[] memory recipients, uint256[] memory amounts) public {
  require(recipients.length == amounts.length, "Mismatched arrays");
  for (uint i = 0; i < recipients.length; i++) {
    transfer(recipients[i], amounts[i]);
    revert("Batch failed");
  }
}
AThe loop condition is incorrect and never runs.
BThe require statement prevents any transfers from happening.
CThe function lacks a payable modifier, so transfers fail.
DThe revert inside the loop causes the entire batch to fail after the first transfer.
Attempts:
2 left
💡 Hint

Consider what happens when revert is called inside a loop.

📝 Syntax
advanced
2:00remaining
Which option correctly defines a batch operation function in Solidity?

Choose the correct Solidity function syntax for a batch token transfer.

A
function batchTransfer(address[] recipients, uint256[] amounts) public {
  for (uint i = 0; i &lt; recipients.length; i++) {
    transfer(recipients[i], amounts[i]);
  }
}
B
function batchTransfer(address recipients[], uint256 amounts[]) public {
  for (uint i = 0; i &lt; recipients.length; i++) {
    transfer(recipients[i], amounts[i]);
  }
}
C
function batchTransfer(address[] memory recipients, uint256[] memory amounts) public {
  for (uint i = 0; i &lt; recipients.length; i++) {
    transfer(recipients[i], amounts[i]);
  }
}
D
function batchTransfer(address[] memory recipients, uint256[] amounts) public {
  for (uint i = 0; i &lt; recipients.length; i++) {
    transfer(recipients[i], amounts[i]);
  }
}
Attempts:
2 left
💡 Hint

Remember how to declare array parameters in Solidity functions.

🚀 Application
expert
3:00remaining
How many successful transfers occur in this batch with partial failure handling?

Consider a batch transfer function that attempts to send tokens to multiple recipients. If a transfer fails, it skips that recipient and continues. Given the code below, how many transfers succeed?

Blockchain / Solidity
uint successCount = 0;
for (uint i = 0; i < recipients.length; i++) {
  try this.transfer(recipients[i], amounts[i]) {
    successCount++;
  } catch {
    continue;
  }
}
return successCount;
A2
B3
C4
D0
Attempts:
2 left
💡 Hint

Assume the second transfer fails, others succeed.