0

The documentation recommends sending Ether from a smart contract using the call keyword:

function sendETH(address payable to, uint256 amount)
public
nonReentrant {
    require(address(this).balance >= amount, "Insufficient funds");
    (bool sent, bytes memory data) = to.call{value: amount}("");
    require(sent, "Failed to send Ether");
}

But as I'm compiling this code I'm getting a warning:

Warning: Unused local variable.
   --> contracts/MyContract.sol:110:21:
    |
110 |         (bool sent, bytes memory data) = to.call{value: amount}("");
    |                     ^^^^^^^^^^^^^^^^^

Is there a way to send ether from a smart contract using the call keyword (as this is the latest recommended method) and avoid this warning?

1 Answer 1

0

The compiler simply warns that this variable is not used in subsequent code. Just leave an empty space instead:

(bool sent,) = to.call{value: amount}("");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.