smartcontractkit / full-blockchain-solidity-course-py

Ultimate Solidity, Blockchain, and Smart Contract - Beginner to Expert Full Course | Python Edition
MIT License
10.67k stars 2.89k forks source link

FundMe- TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address". #1740

Open ellyblueeyes opened 1 year ago

ellyblueeyes commented 1 year ago

Here is the function that throws the error:

function withdraw() public payable onlyOwner { msg.sender.transfer(address(this).balance); for ( uint256 funderIndex = 0; funderIndex < funders.length; funderIndex++ ) { address funder = funders[funderIndex]; addressToAmountFunded[funder] = 0; } //funders array will be initialized to 0 funders = new address; }

I get the following error: CompilerError: solc returned the following errors:

TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address". ----msg.sender.transfer(address(this).balance);

Thank you for help!

itgav commented 1 year ago

msg.sender is of type address. Wrap payable around msg.sender to change it to type address payable -> payable(msg.sender).transfer(address(this).balance)

I believe this was a change made in Solidity version 0.8.`

ellyblueeyes commented 1 year ago

Thank you!