function buyStar(uint256 _tokenId) public payable {
require(starsForSale[_tokenId] > 0, "The star must be available for sale!"); // the star to buy must be in starsForSale mapping
uint256 starPrice = starsForSale[_tokenId]; // get the price of the star for sale
address starOwner = ownerOf(_tokenId); // get the owner of the star
require(msg.value >= starPrice, "You need to have sufficient funds!"); // check the bidding price is greater than or equal to the stars for sale price
_transfer(starOwner, msg.sender, _tokenId);
address payable starOwnerAddressPayable = payable(starOwner);
starOwnerAddressPayable.transfer(starPrice);
if(msg.value > starPrice) {
msg.sender.transfer(msg.value - starPrice);
}
}
The error which is showing up is
ParserError: Expected ';' but got 'payable' address payable starOwnerAddressPayable = starOwner;
Compilation failed. See above.
what is the latest way to overcome this.
function _make_payable(address x) internal pure returns(address payable) { return payable(address(uint160(x)); }
added this ^ function and madestarOwnerAddressPayable = _make_payable(starOwner)
.