Lottery as a Smart Contract: The Business Logic

Jackson Ng
Coinmonks

--

Photo by Alex Chambers on Unsplash

Writing a lottery contract is a great way to learn important Smart Contract concepts such as State, Event and Visibility. In this 3 part series, I will describe the logic and codes behind a Lottery Smart Contract. In developing my Lottery Contract, I used Oraclize, a data carrier service that executes external JSON web services.

You can read part 2 (about execution) here, and part 3 (about codes) here.

Motivation

We know how lotteries work. Bets for some numbers are placed. The lottery closes and a set of random numbers are announced. Winners receive their windfall. This is a perfect candidate to be implemented as a Smart Contract because:

  1. The business case is trustless. Punters are worried that the lottery company may run away when they run out of money to pay out. The lottery companies need to verify if punters really betted the numbers.
  2. Punters are never too sure if the random numbers are really random. In my Lottery Contract, I have not really solved this problem. I will explain why.
  3. Punters needs to queue to receive their prize money. This is a hassle.

The Challenge of Randomness

The challenge in developing Lottery as a smart contract is randomness. To understand why, it is…

--

--