Challenge - 5 Problems
Gas Efficiency Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Gas cost difference between two functions
Consider two smart contract functions that perform the same task but with different gas usage. What is the output showing the gas cost difference?
Blockchain / Solidity
functionA() uses 50000 gas units functionB() uses 30000 gas units Gas price is 20 gwei Calculate the cost difference in gwei.
Attempts:
2 left
💡 Hint
Multiply the gas units difference by the gas price.
✗ Incorrect
The difference in gas units is 20000. Multiplying by 20 gwei gives 400000 gwei saved.
🧠 Conceptual
intermediate1:30remaining
Why does gas efficiency save money?
Which of the following best explains why improving gas efficiency in smart contracts saves money?
Attempts:
2 left
💡 Hint
Think about how gas relates to transaction fees.
✗ Incorrect
Gas efficiency reduces the amount of gas consumed, which directly lowers the transaction fee paid.
🔧 Debug
advanced2:30remaining
Identify the gas inefficiency in this Solidity code
Which line in the code below causes unnecessary gas usage?
contract Example {
uint[] public data;
function addData(uint x) public {
for(uint i = 0; i < data.length; i++) {
if(data[i] == x) {
return;
}
}
data.push(x);
}
}
Attempts:
2 left
💡 Hint
Loops over dynamic arrays cost gas proportional to their length.
✗ Incorrect
Iterating over the entire data array every time addData is called uses more gas as the array grows.
📝 Syntax
advanced2:00remaining
Which code snippet correctly reduces gas usage by avoiding storage writes?
Choose the code snippet that saves gas by minimizing storage writes in Solidity.
Attempts:
2 left
💡 Hint
Look for the simplest way to update a variable.
✗ Incorrect
Using count++ directly is the simplest and most gas-efficient way to increment a storage variable.
🚀 Application
expert3:00remaining
Calculate total gas cost for multiple transactions
A smart contract function costs 45000 gas per call. You plan to call it 100 times. The gas price is 25 gwei. What is the total cost in gwei?
Attempts:
2 left
💡 Hint
Multiply gas per call by number of calls, then by gas price.
✗ Incorrect
Total gas = 45000 * 100 = 4,500,000 gas units. Total cost = 4,500,000 * 25 = 112,500,000 gwei.