If I mint a token and the contract doesn't have all the features I needed from the offset, is there a way I could develop a new contract for a new token and create a way in which people can send the Old token and be returned the new one?
I had a client who was eager to mint coins to distribute to early private investors but the actual way the token will be used or interacted with will change over time, so I'm not too sure how to go about this.
Or perhaps I'm missing something and we can extend the contract.
Best Answer
Yes it is entirely possible. Create contract
A
that is standard ERC20. When it is time to upgrade, create contractB
with your new features.contract
B
has a functionupgradeFrom(address old, uint amount)
Investors then use call
approve(B, uint amount)
onA
. This allows contractB
to retrieve the funds fromA
.Investors then call
upgradeFrom(B, uint amount)
, and the upgradeFrom function withdraws the funds fromA
and does any other logic to set up the investor in contract B.Another way:
If you don't care about contract
A
after contractB
is in production, you can just have a single function in contractB
calledupgrade()
that checks the balance of the sender in contractA
and updates it in contractB
. You will also want to make sure you record who has already upgraded as people could call the function multiple times.