Bird
Raised Fist0
Blockchain / Solidityprogramming~20 mins

Sending Ether (transfer, send, call) in Blockchain / Solidity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Ether Transfer 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 Solidity code when sending Ether using transfer?

Consider the following Solidity contract snippet. What happens when sendEther is called with 1 ether?

Blockchain / Solidity
pragma solidity ^0.8.0;

contract TransferExample {
    event Sent(address to, uint amount);

    function sendEther(address payable recipient) public payable {
        recipient.transfer(msg.value);
        emit Sent(recipient, msg.value);
    }
}
AThe transaction returns false if the recipient rejects the Ether.
BThe transaction always succeeds regardless of recipient's fallback gas usage.
CThe transaction reverts if the recipient's fallback function uses more than 2300 gas.
DThe transaction sends Ether asynchronously and does not wait for confirmation.
Attempts:
2 left
💡 Hint

Recall that transfer forwards a fixed gas stipend of 2300 gas.

❓ Predict Output
intermediate
2:00remaining
What does the send method return in this Solidity example?

Given this contract snippet, what is the value of success after calling sendEther?

Blockchain / Solidity
pragma solidity ^0.8.0;

contract SendExample {
    function sendEther(address payable recipient) public payable returns (bool) {
        bool success = recipient.send(msg.value);
        return success;
    }
}
ATrue if the Ether was sent successfully, false otherwise.
BThrows an exception on failure instead of returning false.
CAlways true, send never fails.
DReturns the amount of gas used by the send operation.
Attempts:
2 left
💡 Hint

Remember that send returns a boolean indicating success or failure.

❓ Predict Output
advanced
2:00remaining
What is the output of this Solidity code using call to send Ether?

Analyze the following contract. What does the sendViaCall function return when called with 1 ether?

Blockchain / Solidity
pragma solidity ^0.8.0;

contract CallExample {
    event Sent(address to, uint amount, bool success);

    function sendViaCall(address payable recipient) public payable returns (bool) {
        (bool success, ) = recipient.call{value: msg.value}("");
        emit Sent(recipient, msg.value, success);
        return success;
    }
}
AAlways reverts if the recipient rejects the Ether.
BReturns true if the Ether was sent successfully, false otherwise.
CReturns the amount of gas used by the call.
DReturns false if the recipient's fallback function uses more than 2300 gas.
Attempts:
2 left
💡 Hint

Recall that call returns a boolean success and forwards all remaining gas by default.

🧠 Conceptual
advanced
2:00remaining
Which statement correctly describes the difference between transfer, send, and call for sending Ether?

Choose the option that best explains the key difference between transfer, send, and call when sending Ether in Solidity.

A<code>transfer</code> and <code>send</code> forward 2300 gas, <code>call</code> forwards all remaining gas and returns success status.
B<code>transfer</code> forwards all gas, <code>send</code> reverts on failure, <code>call</code> forwards 2300 gas.
C<code>send</code> throws on failure, <code>transfer</code> returns false, <code>call</code> always succeeds.
D<code>call</code> forwards 2300 gas, <code>send</code> forwards all gas, <code>transfer</code> returns success status.
Attempts:
2 left
💡 Hint

Think about gas forwarding and error handling differences.

🔧 Debug
expert
3:00remaining
Why does this call-based Ether transfer fail unexpectedly?

Consider this contract snippet. The sendViaCall function returns false unexpectedly when sending Ether to a contract with a fallback function that uses more than 2300 gas. Why?

Blockchain / Solidity
pragma solidity ^0.8.0;

contract Receiver {
    fallback() external payable {
        // Uses more than 2300 gas
        for (uint i = 0; i < 1000; i++) {}
    }
}

contract Sender {
    function sendViaCall(address payable recipient) public payable returns (bool) {
        (bool success, ) = recipient.call{value: msg.value, gas: 2300}("");
        return success;
    }
}
ABecause the call does not send any Ether due to missing value parameter.
BBecause call always forwards all gas, so the fallback function runs out of gas.
CBecause the fallback function is not payable, causing the call to fail.
DBecause the call explicitly limits gas to 2300, which is insufficient for the fallback function.
Attempts:
2 left
💡 Hint

Check the gas parameter in the call and the fallback function's gas usage.

Practice

(1/5)
1.

Which Solidity function automatically reverts the transaction if sending Ether fails?

easy
A. approve
B. send
C. call
D. transfer

Solution

  1. Step 1: Understand transfer behavior

    transfer sends Ether and automatically reverts if the transfer fails.
  2. Step 2: Compare with other methods

    send returns false on failure without reverting; call requires manual check; approve is unrelated to sending Ether.
  3. Final Answer:

    transfer -> Option D
  4. Quick Check:

    Automatic revert on failure = transfer [OK]
Hint: transfer always reverts on failure, no manual check needed [OK]
Common Mistakes:
  • Confusing send with transfer behavior
  • Thinking call auto-reverts on failure
  • Mixing approve with Ether sending
2.

Which of the following is the correct syntax to send 1 Ether using send in Solidity?

recipient.?{value: 1 ether}();
easy
A. send
B. transfer
C. call
D. approve

Solution

  1. Step 1: Recall send syntax

    send is called as recipient.send{value: amount}() in Solidity 0.6+.
  2. Step 2: Match syntax with options

    Only send matches send method usage for sending Ether.
  3. Final Answer:

    send -> Option A
  4. Quick Check:

    send syntax = recipient.send{value: 1 ether}() [OK]
Hint: send uses .send{value: amount}() syntax [OK]
Common Mistakes:
  • Using transfer syntax with send
  • Confusing call syntax with send
  • Using approve which is unrelated
3.

What will be the output of the following Solidity code snippet?

bool success = recipient.send{value: 1 ether}();
if (!success) {
    revert("Send failed");
}
medium
A. Transaction reverts if send fails
B. Transaction always succeeds without revert
C. Compilation error due to syntax
D. Transaction succeeds but ignores failure

Solution

  1. Step 1: Analyze send return value

    send returns false if sending Ether fails, but does not revert automatically.
  2. Step 2: Check revert condition

    The code checks !success and calls revert manually, so transaction reverts on failure.
  3. Final Answer:

    Transaction reverts if send fails -> Option A
  4. Quick Check:

    send returns false + manual revert = revert on failure [OK]
Hint: send returns bool; revert manually on false [OK]
Common Mistakes:
  • Assuming send auto-reverts
  • Ignoring manual revert check
  • Thinking code always succeeds
4.

Identify the error in this Solidity code snippet that uses call to send Ether:

(bool sent, ) = recipient.call{value: 1 ether}();
require(sent, "Failed to send Ether");
medium
A. Missing gas parameter in call
B. Incorrect syntax for call
C. No error; code is correct
D. Should use send instead of call

Solution

  1. Step 1: Review call syntax

    The syntax recipient.call{value: 1 ether}() is correct for sending Ether with call.
  2. Step 2: Check error handling

    The code checks sent boolean and reverts if false, which is proper error handling.
  3. Final Answer:

    No error; code is correct -> Option C
  4. Quick Check:

    call with value + require check = correct usage [OK]
Hint: call needs manual success check; this code does it [OK]
Common Mistakes:
  • Thinking gas parameter is mandatory
  • Confusing call syntax with send or transfer
  • Ignoring manual success check
5.

You want to send Ether to a contract that might consume more than 2300 gas on fallback. Which method should you use to ensure the transfer succeeds?

hard
A. transfer
B. call
C. approve
D. send

Solution

  1. Step 1: Understand gas limits of transfer and send

    transfer and send forward only 2300 gas, which may be insufficient for complex fallback functions.
  2. Step 2: Use call for flexible gas forwarding

    call allows forwarding all available gas, ensuring the receiving contract can execute complex logic.
  3. Final Answer:

    call -> Option B
  4. Quick Check:

    call forwards all gas, suitable for complex fallback [OK]
Hint: Use call to forward all gas for complex fallback [OK]
Common Mistakes:
  • Using transfer or send which limit gas to 2300
  • Confusing approve with sending Ether
  • Ignoring fallback gas requirements
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