solidity刚学习 "send" and "transfer" are only available for objects怎么解决

小弟刚学习solidity,写个发水龙头的币的代码
pragma solidity ^0.8.18; contract Faucet { function withdraw(uint amount) public { require(amount < 1000000000000000000); msg.sender.transfer(amount); } }

报以下错误:
pragma solidity ^0.8.18;
contract Faucet {
function withdraw(uint amount) public {
require(amount < 1000000000000000000);
msg.sender.transfer(amount);
}
}
请问大神们怎么解决

请先 登录 后评论

1 个回答

dan

合约代码改为:

// SPDX-License-Identifier: MIT

pragma solidity ^0.8.18;

contract Faucet {
    function withdraw(uint256 amount) public {
        require(amount < 1000000000000000000);
        payable(msg.sender).transfer(amount);
    }
}
请先 登录 后评论
  • 1 关注
  • 0 收藏,1224 浏览
  • 张晓峰 提出于 2023-11-05 20:28