[Ethereum] How to Retrieve Remaining Tokens from ICO Contract

contract-developmenticosolidity

So I created an ICO contract based on a token with a set initial supply and no mint function. I publish this contract and then send the associated tokens to the contract. I can send ether and receive it in the desired account and the new tokens are sent to the correct account.

However, if not all of the tokens that were sent to the contract are purchased during the ICO, they just seem to disappear. Is there a simple way to retrieve the remaining coins? I have tried self destruct and suicide but I think those apply to the ether that would be stored in the contract address.

Thanks for any help!

Brian

Best Answer

If your contract(s) are already deployed, you're out of luck.

On the other hand if you are still developing either the token or the crowdsale, there are a number of ways you can move the tokens around.

Firstly, the token balance on your crowd sale contract is just a value allocated within the token contract, so you can just have a function on your token contract allow you to directly reassign the balance from the crowd sale contract.

uint256 unsold = balances[saleaddress];
balances[saleaddress] = 0;
balances[someLocation] += unsold;

A better option perhaps, is to have the crowd sale contract handle it. In this case you can do something like

function withdrawUnsoldTokens()
{
    require(msg.sender == ownerAddress);
    ERC20 mytoken = new ERC20(tokenAddress);
    uint256 unsold = mytoken.balanceOf(this);
    mytoken.transfer(ownerAddress, unsold);
}
Related Topic