Here is the code for someone performing a transfer of my token

function transfer(address to, uint256 value) public returns (bool) {
    require(value <= _balances[msg.sender]);
    require(to != address(0));

    uint256 tokensToBurn = value.div(100000).mul(7);
    uint256 tokensToDividend = value.div(100000).mul(3);
    uint256 tokensToTransfer = value.sub(tokensToBurn).sub(tokensToDividend);

    _balances[msg.sender] = _balances[msg.sender].sub(value);
    _balances[to] = _balances[to].add(tokensToTransfer);

    _totalSupply = _totalSupply.sub(tokensToBurn);

    emit Transfer(msg.sender, to, tokensToTransfer);
    emit Transfer(msg.sender, address(0), tokensToBurn);
    emit Transfer(msg.sender, ?, tokensToDividend);
    return true;

As you can see, 0.007% of the tokens are burned, and I want 0.003% to be sent to everyone who holds the token. I've put a '?' where I want the holder addresses to go. How do I go about giving out the tokensToDividend value equally among all holders?

2 Answers 2


Actually, you should not send part of a transaction to all token holders. That is possibly infinitely expensive to do (because your list of token holders can grow indefinetely, I assume). There's no way of doing exactly that in the EVM.

Just to clarify, imagine you have ten thousand token holders and someone just wants to send 1 token to a friend. How much gas will that person pay to make that 1 token transfer? She will have to pay for 9,999 transfers! Most probably, the transaction will just fail because it will run out of gas.

Note that that will hold even if you are just emitting events, instead of actually using .transfer

You should change your approach in order to meet your objective. You'll need to work with a dividends proportion, so that you can calculate how much a given user is entitled to when that user wants to withdraw dividends, or consult how much she owns.

You'll also need to track how much a user has withdrawn before.

The full implementation is far too complex to put here, but you can follow these three links for a more in-depth explanation and to see some examples:



ERC20 Token and effective way to store dividends

Also, take a look at this: https://github.com/Roger-Wu/erc1726-dividend-paying-token

I think this last one is exactly what you're looking for.


If you have stored the list of all the account holders in an array, you can iterate over this array and transfer them dividend and emit the event as well.

But better instead of transferring in a loop, you can create a dividend mapping and update the dividends of each person when needed and emit an event. The dividend eligible people can then withdraw this dividend when they want to.

  • He needs to be careful on looping over an array as he can risk of going out of gas Jul 17, 2019 at 10:25

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.