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
require(tokenContract.transfer(msg.sender,_numberOfTokens));
// 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));
selfdestruct(admin);
}
}