Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

solidity

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

like image 682
Пиздатый Инвестор Avatar asked Oct 29 '25 05:10

Пиздатый Инвестор


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);
like image 183
Petr Hejda Avatar answered Oct 31 '25 11:10

Petr Hejda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!