1

I an in search way to send tokens from a contract to a list of all addresses (an array or mapping) without using a loop(as I know gas fees for this can become a huge issue).

I have a contract, that when someone new enters it, I want to send the balance of a specific token to all the other addresses that are currently "participating" based on a % they hold of another Token(the contracts internal token). I cannot think of a way of either setting the "balance" manually, or paying out automatically, that does not require looping through a list.

Simply updating "balances" based on a "ratio" does not seem to work as its a staking contract and this is a secondary token (such as a dividend token) that we are trying to account for. There for, it seems necessary to do bulk Transfers (similar to how dividend tokens do them I am assuming) so that new entries do not receive rewards they have not earned.

Any assistance is greatly appreciated.

1

1 Answer 1

0

I believe that there is no other method apart from looping. You might be overestimating how big of an issue gas fees are. At the end of the day, you need to make the transfer to all the addresses anyway, so that gas needs to be paid by someone. I think that the reason people warn to be careful with gas and loops is because it's not that hard for your loop to become unbounded or obtain a bound larger than you have provisioned for which might lead to total gas being higher than gas of block which will fail the tx. If you take proper care of your bound, you should be good.

@ismael's answer in the comments is an interesting one. It appears that deflationary coins (e.g. Safemoon) tackle this challenge by mathematically adjusting the supply of tokens in circulation. Obviously you cannot simply apply that in a smart contract though.

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.