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??



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.


You are correct in saying selfdestruct(address) will transfer the remaining either to the address specified.

Ether is the only built in currency in the network, and therefore handled this way.

Tokens in a contract are actually stored in which ever manner the contract creator decides. Typically in a simple token contract it's just a mapping of addresses to balances. So destroying the contract also destroys the storage and tokens.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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