I am still pretty new to Ethereum and smart contract but for a couple of last weeks I have been developing a smart contract for a gambling website project (studying purposes).

In the smart contract I have a function (called by the manager of smart contract) that group up all winners of a jackpot, returns to them what they bet, and then also draw random prices. So for every person who entered the jackpot, there is one iteration of a big function (drawing prices, returning initial bet).

I learned the hard way that if let's say 1000 people enter the jackpot and I call the function to reward all winners it consumes more than 6 milion gas.

How do people get around this? I would be even willing to pay considerable amount of money for running this function if so many people enter (because I can charge fees and use them to pay for this) but then there is block gas limit and there is no way I can even run this function to the end at all.

1 Answer 1


You have at least a few alternatives:

1) Run the processing in batches. So in first transaction process the first 100 entries, the next 100 in the next transaction and so on.

2) If possible, run all the logic when the user enters the lottery already so there would be no post-processing. This is of course not possible with certain kinds of projects.

3) Second layer solutions, such as Plasma or state channels. Unfortunately this is all still very new and there are not very many working examples for this yet. Also requires quite much technical knowledge.

4) Do the processing outside blockchain in centralized fashion. So when the contract is ready, your backend system does all the processing and then sends transaction(s) to the contract and/or participants with required stuff (rewards for example).

When making a lottery/gambling contract make sure you understand the problems with random number generating inside the blockchain. Read more for example here: How can I securely generate a random number in my smart contract?

  • Thanks for ideas. After all I think the only viable option for me is to go with batches. 2) is not possible since the calculations are dependent on variables known only after finishing the jackpot (number of people entered, value in different tokens etc.). 3) is probably to complex for me and 4) is not possible since to many data is hidden behind mappings inside the contract
    – lemme
    Oct 8, 2018 at 12:44

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.