full-blockchain-solidity-course-py icon indicating copy to clipboard operation
full-blockchain-solidity-course-py copied to clipboard

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

Open ellyblueeyes opened this issue 2 years ago • 2 comments

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!

ellyblueeyes avatar Oct 10 '22 17:10 ellyblueeyes

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.`

itgav avatar Nov 27 '22 15:11 itgav

Thank you!

ellyblueeyes avatar Nov 27 '22 18:11 ellyblueeyes