Solidity – Fixing Invalid Type for Argument in Function Call: Address to Address Payable

payableselfdestructsolidity

function endSuply() public {
    require(msg.sender == admin,"only admin can end the token sale");
    require(tokenContract.transfer(admin, tokenContract.balanceOf(address(this))),"balance not transferring");

    selfdestruct(admin);
}

here admin is a state variable declared as address admin;

But the error pops up and doesn't compile !

I just need to disable the contract, how can it be done ?

Best Answer

Elsewhere in the contract, find address admin; and declare it as address payable admin;.

Alternatively, selfdestruct(msg.sender); because require(msg.sender == admin); ensures they are the same and msg.sender should be payable.

A word of caution. selfdestruct is an inelegant way to stop a contract and could lead to non-trivial problems. Consider using Open Zeppelin Pausable.sol instead.

Hope it helps.

Related Topic