PatrickAlphaC / fund_me

49 stars 83 forks source link

"transfer" are only available for objects of type "address payable", not "address". #19

Closed Kam0teQ closed 2 years ago

Kam0teQ commented 2 years ago

Hi, can anyone help me, I was trying on this code but whenever I compile it, remix gives me an error saying TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address". I got this error from the function withdraw() public payable onlyOwner {msg.sender.transfer(address(this).balance; for(...) }. I just copied and pasted the code from the github repo and change the import for the aggregatorv3interface to import "https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol"; and removed the SafeMath import line. I'm also using compiler version 0.8.7. Thanks in advance.

Screen Shot 2022-10-13 at 10 44 12 AM
PatrickAlphaC commented 2 years ago

Yep! This was updated in newer versions of solidity. Just make your addresses payable

payable(msg.sender).transfer(...);
Kam0teQ commented 2 years ago

Thanks a lot Patrick! Actually I was also able to make it compile by using: uint256 contractBalance = address(this).balance; payable(msg.sender).transfer(contractBalance); inside the withdrawal function. I know this issue is already closed, but could you help on how would I be able to keep up to date with syntax changes such as this in Solidity?