I am trying to send funds to the users who deposited ethers to my contract. I am currently achieving this by having the list of address and looping through them sending those addresses ethers. Right now this works for 2-3 users (tested).

My concern now is, if there are about 1000 users to whom I need to reward ethers. Is it sufficient if my contract has enough ethers to send fund + gas ? or should the transaction that calls the rewarding method needs to send the sufficient ethers in order to execute the transfers?

I have seen a couple of well known contract making users withdraw their reward instead of sending them automatically. Which one works? if both works then which method is recommended?


HIGHLY recommended that you require users to pull their funds instead of push them to the users with a for-loop.

  1. A lot harder to implement with a large amount of users, need to run though the loop until getting low on gas, hold position in the loop, and then wait until the next execution. If you don’t implement this then one one will get paid (ever!) when your number of users is too large to loop through without breaking the gas limit.

  2. An even bigger problem is that it is a huge security issue. What if one of the users makes his fallback function revert(); then after him, no one would be able to receive their ether because the loop will always fail (revert the entire execution) when paying out this mischevious user.

There are lots more issues with the push method of sending payments, but these should be enough.

  • 1
    I had speculations about the first reason you gave. That was the reason I posted this question. But the second reason I didn't even think of. Thanks a lot of taking time to answer my question. Really appreciate it. Oct 24 '17 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.