[Ethereum] Will contract selfdestruct also return tokens

erc-20selfdestructsoliditytokens

If I have tokens assigned to a smart contract, will "killing" the contract send leftover tokens to the owner of the contract? I know that remaining Ether stored in the contract is sent to owner in selfdestruct(owner), but what about tokens that are stored in the contract? It looks like I would have to manually right a function to disperse remaining tokens before self destruct, correct??

Best Answer

No

In your function that calls selfdestruct(owner), you would also need need to call the (ERC20) token's contract transfer function. The code would look like:

SomeToken tok = SomeToken(tokenAddress);
uint tokenBalance = tok.balanceOf(address(this));
tok.transfer(owner, tokenBalance);

Make sure that owner is an externally owned account (EOA) or a contract that can access the tokens.

Reminder to test thoroughly, that the tokens are transferred and that the owner can transfer the ETH and tokens it receives.


The other case is what @Ian mentions and if your contract issued tokens to people, and you selfdestruct the contract, people's tokens disappear: your contract was the ledger that recorded token balances and it disappeared.

Related Topic