TypeError: Invalid type for argument in function call. Invalid implicit conversion from address to address payable requested. selfdestruct(admin);

pragma solidity >=0.4.21 <0.6.0;
import "./DappToken.sol";
contract DappTokenSale{
    address admin;
    DappToken public tokenContract;
    uint256 public tokenPrice;
    uint256 public tokensSold;

    event Sell(address _buyer, uint256 _amount);

    constructor(DappToken _tokenContract, uint256 _tokenPrice) public {
        //Assign an admin
        admin = msg.sender;
        //token Contract
        tokenContract = _tokenContract;
        //Token Price
        tokenPrice = _tokenPrice;
    // multiply function
    function multiply(uint x, uint y) internal pure returns (uint z) {
        require(y == 0 || (z = x * y) / y == x);
    // Buy Token
    function buyTokens(uint256 _numberOfTokens) public payable{
        // Reqiured that value is equal to tokens
        require(msg.value == multiply(_numberOfTokens, tokenPrice));
        // Required that the contract has enough token
        require(tokenContract.balanceOf(address(this)) >= _numberOfTokens);    
        // Required that a trnasfer is successfuly
        // keep track of number of token sold
        tokensSold += _numberOfTokens;

        // Trigger sell event
        emit Sell(msg.sender, _numberOfTokens);

    // Ending Token DappTokenSale
    function endSale() public {
        // Require admin
        require(msg.sender == admin);
        // Transfer remaining dapp token to admin
        require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))));
        // UPDATE: Let's not destroy the contract here
        // Just transfer the balance to the admin
        // admin.transfer(address payable(this).balance);
        // selfdestruct(address payable admin);
        // selfdestruct(address payable admin);
        //address payable adminAddress = address(uint160(admin));

2 Answers 2


Change line 4 to:

address payable admin;

Hope it helps.


=> add this code in first line // SPDX-License-Identifier: MIT

=> Change address admin; to address payable admin;

=> add emit before every transaction event like emit Sell(msg.sender, _numberOfTokens);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.