full-blockchain-solidity-course-py
full-blockchain-solidity-course-py copied to clipboard
FundMe- TypeError: "send" and "transfer" are only available for objects of type "address payable", not "address".
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!
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.`
Thank you!