1

My tokens will be distributed to users after a crowd sale. The amount they receive depends on how much everyone has donated, so the distribute function must be performed after the end of the crowdsale.

My first instinct was to have the distribute function iterate through an array, calculating and sending each user's token allotment in one fell swoop. But since the number of participants is unpredictable, there's a chance that operation will require more gas than the block gas limit.

A better alternative seems to require individual members to execute the "distribute" function individually, after the crowd sale.

Practically speaking, does it matter?

1

Practically speaking..?

No, it makes no difference. It just shifts responsibility.

There are a number of ways you can do it though such that you can maintain responsibility though..

Why not just allocate the tokens to x people at a time (such that you stay under the gas limit), removing those addresses from the array after the tokens have been allocated..

Edit New information.

The Solidity docs have an example for a SimpleAuction contract.

They utilise the described pattern for their refunding of bids (once outbid) whereby the user has to request their refund.

On this basis I would say that requesting that individual members call distribute would be a reasonable thing to do.

  • So even if the array were large, say a million addresses, that wouldn't exceed gas limit? There's no danger of that for this crowd sale, but I'm wondering, for future contracts, about the computational limits of any one transaction. – will_durant Aug 11 '17 at 18:40
  • If you loop through all 1 million then yes it probably would. If you take 10 at a time, and call it 100,000 times then no. I don't have any benchmarks but you can use a test network to test the limits yourself. – Thomas Clowes Aug 11 '17 at 18:45
  • I see. So I guess putting responsibility on each address do it is probably the best way, to spread out the cost, for cases when there's a lot of data. – will_durant Aug 11 '17 at 22:02
  • Yes. See edit.. – Thomas Clowes Aug 11 '17 at 23:19

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.