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?

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, privacy policy and cookie policy

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