2

I'm gona create new version from my f***d of ERC20 token(the problem where in somewhere else not in the ERC20 implementation), I already know how to burn the old Tokens and send out the new one if the user request it.

But it will be much better to doing it once right after the Contract init.

I get that I can use the mapping to get the addresses,

contract OLD_CONTRACT {
    mapping (address => mapping (uint => uint)) public balances;

But then how I can use these addresses in some loop to transfer the exact number of my new Tokens to every address. Most importantly how I can do it in some efficient way?

0

You can't really. Since it's stored in a mapping, you'd need access to the balance of every address of that contract since the addresses themselves aren't actually stored on that contract. However, if you can freeze the balances of OLD_CONTRACT, you can have your balances function on the new contract check if the balance has been initialized on the new contract, and if it hasnt't, set it to the balance of the user on the old contract.

Another option is to use https://github.com/Giveth/minime, which is a token that allows "forking" at a given block number.

Alternatively, you can have an "upgrade" mechanism where they people would approve your contract to transfer their tokens from the old contract, then they call an upgrade function on your new contract that burns all their old tokens and gives them the new tokens.

0

A technique is to collect all addresses that were used in Transfer event. All addresses with non-zero balance should appear at least in one Transfer event.

Then they run a script and set the balance in the new token with the value of the old token. You can make queries first and prepare batch transfers to minimize costs.

For all of this to work you need to be able to freeze the old token transfers before the migration/upgrade.

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.