Solidity

使用“call”關鍵字發送 Ether 時的編譯器警告

  • November 28, 2021

該文件call建議使用以下關鍵字從智能合約發送乙太幣:

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");
}

但是當我編譯這段程式碼時,我收到了一個警告:

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

有沒有辦法使用call關鍵字從智能合約發送乙太幣(因為這是最新推薦的方法)並避免此警告?

編譯器只是警告此變數未在後續程式碼中使用。只需留下一個空白空間:

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

引用自:https://ethereum.stackexchange.com/questions/114451