I am learning to write ERC-20 contracts and I try to emulate common stocks.

I would like some tips on how to implement it.

How to issue new tokens? - Emulate issuing new stocks. How to destroy tokens? - Emulate stock buyback. How to split tokens? - Emulate stock split (every token becomes multiple of original tokens).

1 Answer 1


How to issue new tokens: simply assign tokens to some wallet without reducing the balance of another

How to destroy: reduce the balance of a wallet without increasing the balance of another one

How to split: if you want to to create two times the original, go through each balance and double it. This problem with this approach is that if there are lots of owners, you may face problems with looping through all of the token balances (going above the gas limit). So you may have to implement functionality to do this in batches, in some way.

  • So you create non-public functions which would do it? And only the owner of the contract could issue them? Is it possible to loop over all balances? Maybe it would be better to create some kind of ratio that is applied on a base value when the transaction is made and when asking for balance? Would that approach work? Feb 7, 2021 at 16:06
  • Well the functions have to be public (or external) so the owner can call them. But yes, probably you want to restrict access to those functions. You can try your approach, but it may cause problems when multiple operations are performed and it gets tricky to know what the real amount should be. Feb 7, 2021 at 16:14
  • So functions have to check who calls them against some list, there is nothing like restricting them only to contract owner? (Sorry if my questions are trivial.) Maybe I could issue something like transaction restrictions for a certain period of time before and after the token split? Feb 7, 2021 at 16:18
  • There is no default functionality in contracts. Whatever you want, you have to code. So there is also no "owner" unless you create such functionality. For example access restrictions are often done by whitelisting addresses - so only owner address can perform some actions. Feb 7, 2021 at 16:26
  • Please post a new question (or search for existing answers) if you have further questions Feb 7, 2021 at 16:26

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.