1

I have a contract and I have ether in it. How can I distribute balance of contract between owner`s tokens base on percentages?

4
  • What’s the actual issue? You know the total number of tokens, you know how many tokens each owner is. So you have the percentages. Make a withdraw function that will send a percentage calculated above to the token holder account.
    – Strelok
    Sep 21, 2017 at 14:36
  • I need send on all holders. And I don`t understand how to get their addresses and value tokens in one function. How interate balances. Sep 21, 2017 at 17:46
  • that is not possible. Mappings cannot be iterated in Solidity. You would have to maintain an additional array of token holder addresses that you will have to iterate if you want to distribute to all token holders.
    – Strelok
    Sep 21, 2017 at 23:54
  • Maybe it is possible, because in documentation takes link on interable mapping solidity.readthedocs.io/en/develop/types.html#mappings Oct 25, 2017 at 14:22

2 Answers 2

2

If you still need an answer, try this excellent approach https://medium.com/@weka/dividend-bearing-tokens-on-ethereum-42d01c710657.

The key point here is that it is not you who distributes the ether among holders but holders should withdraw their share themselves.

Contract with ether should watch token transfers and adjust ether sums that are to be paid to those addresses.

The article describes 2 cases: one for fixed token supply and one for variable token supply.

1
0

In now day I have solution this task: https://github.com/poperechnyi1/iterable-Mapping-ERC20 I used iterable mapping: https://github.com/szerintedmi/solidity-itMapsLib

Your Answer

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

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