hope you can assist me on this matter:


One year ago a token has been created. Right now, the developer wants to add some nice feature for the users.

The users need to send X amount (let's call it 100) tokens to a new contract, where those 100 tokens are swapped against 1 new token.

The caveat is that the developer has no more owner acccess to the original contract.

Now the question is;

  • How can a new contract receives X amount of old tokens.
  • How can the amount sent be checked.

So i'm looking for a way to swap coins from the old contract.

Thank you for helping me out :-)

3 Answers 3


It can be solved, and the programming part is not that difficult, what's more difficult is having the users actually do the swap as they will have to do it manually.

On your old token contract you have the balances of your token holders. Say:

Contract OLD_TOKEN: balances[0X_USER_A] = 1000; 

You will want to have this now:

Contract OLD_TOKEN: balances[0X_USER_A] =    0; 
Contract NEW_TOKEN: balances[0X_USER_A] = 1000; 

For this to happen, you would have to code the NEW_TOKEN contract so it can be paid with OLD_TOKEN and give 0X_USER_A that balance.

The way that would have to be done is having the user call approve on his OLD_TOKEN, granting your NEW_TOKEN an allowance of the old tokens.

Once your new contract has said allowance, you or each of your users would have to call a function of NEW_TOKEN that transfers the old balance to the new contract and then mints / assigns a balance of NEW_TOKEN to the user.

So, basically, what this NEW_TOKEN contract would do is use the OLD_TOKENs of your user to pay for tokens this NEW_TOKEN contract has. But for it to be able to do that, first the user has to approve the new contract to use his tokens.

As far as I can tell, this is the only way to do it, which has a suboptimal user experience as your users would have to manually approve on the old token and then call another function on your new token to redeem the tokens.

  • This is a nice start, but i'm more intrested of users just sending the tokens to the new contract, where they are stored, and send out the new token to the sender address. Eventually, if the user decides to get the 'old' token back, he does the opposite. He sends back the new, and receives the old that are just sitting on the contract.
    – Bazookaah
    Nov 18, 2017 at 12:26

I think there is a misunderstanding here, your new contract will not receive the old tokens in the way that is described by the others. If you send tokens to the new contract's address this will be reflected in the balance of the old contract and not in the balance of the new one and the new contract can't know that you sent it tokens neither, because contracts will not receive event notifications from other contracts.

What you could do is to access the balance of the old contract's tokens from your new contract and assign the corresponding tokens.

For this, you need to index the mapping variable using the addresses of the token holders. The easy way to get the addresses is to ask them to send a transaction of 0 ether to your new contract, then using the sender address you index the balance of the old contract (balanceOf is public) you can proceed to assign the corresponding new token based in the sender balance in the old contract.

this may be gas expensive if you have a lot of token holders but will work.

I hope this helps.


ERC20 (https://theethereum.wiki/w/index.php/ERC20_Token_Standard)

How can a new contract receive an amount x of old tokens?

If your contract is ERC20-compatible, it should be fairly straightforward. It's important for the new contract's totalSupply to be exactly 1% of the old one's (so that 100 old -> 1 new can work nicely). Alternatively, you could have your new contract support "minting" (totalSupply changes):

  • Ask your users to approve of a new/migration contract's address to spend their old funds (the approve method)
  • Then, from the new/migration contract listen for Approval events and use transferFrom to move their tokens to the new contract's entry in the old one's balanceOf record. If a correct Transfer event came through, increase the user's balanceOf in the new Token by the event's amount divided by 100.

The end result should be that all the migrated old money is in the old contract's balanceOf entry which belongs to the new token/migration contract.

How can the amount sent be checked?

Checking the Transfer events would be the most straightforward, but it wouldn't hurt to check that balanceOf changed accordingly (Better safe than sorry!)


In the case of a non-ERC20 contract, that depends. In general, what you need is a way to reliably check balance changes (e.g. listen for events that transfer to a designated account). Then, you'd want to add the transfered amount to a given user's entry in the new token's balance record.

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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