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

Viewed 3350
function endSale() public {
        require(msg.sender == admin);
        require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));


        admin.transfer(address(this).balance);
    }
}

error line ---> admin.transfer(address(this).balance);

can someone help me with this thank you

1 Answers

Address literals have the type address instead of address payable. They can be converted to address payable by using an explicit conversion, e.g. payable(0xdCad3a6d3569DF655070DEd06cb7A1b2Ccd1D3AF).

Source: Solidity v0.8.0 Breaking Changes

What it means, is that since Solidity 0.8, address is not payable by default. And if you want to send it native currency, you need to cast it to payable first.

Example:

payable(admin).transfer(address(this).balance);
Related