Using steemd.com to run a lottery type competition on steemit.

in #steemit7 years ago (edited)

Currently I am running a little lottery type competition on steemit, where people can earn lottery tickets by giving feedback on a work of fiction. As, if i get at least one more contestant, the lotery will commence on August 1st, I started thinking about how to draw the ticket in a way that should provide the contestants with some trust about the draw being honest. After all, it might be that a friend of mine enters the competition, and what is to keep me from just claiming he or she won the lottery? So we set out to find a way to show the contestants that I am unable to commit any such fraud, that they can trust the ticket that wins does so by pure chance or at the very least by circumstances outside of my own power.

Steemd.com is a place where we can look at things happening in the steemit block chain, every day there are many many transactions taking place that are combined as small groups in blocks. Tens of thousands of blocks a day at this moment. This gave me an idea for the lotery. If we know that a multiple of ten thousand blocks are created every day, then we know some block each day will be the first block of the day with a block number that can be divided by ten thousand. As my lottery is supposed to commence on August 1st, I can thus announce that I will making my draw of the winning ticket using the that specific block.

Let's look how this works using steemd.com. We can construct an URL using a block identification number. Such an URL will look something like https://steemd.com/b/14000000, now by incrementing the block identifier with different values, incrementing in multiples of 10,000, we can locate the actual first block for a specific day with a number dividable by 10,000. Today it's Juli 27th, and by incrementing the block number 10,000 at a time we discover that today's first block id that was dividable by 10,000 is block 14,040,000.

Now if we look at the steemd.com page for this block, we notice a link named Show raw block data. Clicking that link will expose a lot of data, most of what we aren't particularly interested in. The one thing of interest here is the field named witness_signature. The content of this field should be enough for us to base our draw on.

Now for our draw to commence we need to do a few more things.

  • We check the exact time-stamp of the draw.
  • On the lottery content page we sort the responses by age
  • Entries newer than the moment of the draw are discarded.
  • We now construct an age sorted array with the oldest entries first and the latest entries last.
  • We apply lottery competition rules as set when the lottery was created.

Note that it's important to let a lottery run for at least a week so you are unable to change the rules of the game at the moment of the draw.

Lets say we get the following result from these actions:

  • John : One ticket
  • Robert : One ticket
  • Bjarne : Two tickets
  • Gwen : One ticket
  • Rachelle : One ticket
  • Wietse : Three tickets
  • Xavier : One ticket

Now we move on to starting python to make the draw. The first thing we do is enter our witness_signature and our ordered list of ticket holders:

witness_signature = "205734801b825c13f0b2452566f879148db8c91e627c11ab1288bb29dc5749e1226fd4d6f68617f92147bdcb9ca7aefd818c01a63b71e80a377f4280e3c362b3be"
ticket_holders = contestants = ["John","Robert","Bjarne","Bjarne',"Gwen","Rachelle","Wietse","Wietse","Wietse","Xavier"]

Now we can do a fair random and fraud resistant draw using the following command in python:

winner = ticket_holders[int(witness_signature,16) % len(ticket_holders)]
print "And the winner is:", winner   

In this example, today's winner would be Gwen.

A little attempt to write a script to do this stuff.

Any improvement suggestions highly appreciated. Running the script will give the following results:

If my current lottery style contest reaches the minimum contestant number before the deadline, I shall be using this same construct described above for determining the winner. I hope the above description is convincing enough for my contestants to relay confidence in the draw being performed in a fraud resistant fashion. I also hope that others who are running lottery type competitions might benefit from the simple technique described above to make the fraud free nature of their draws 100% transparent.

Coin Marketplace

STEEM 0.17
TRX 0.16
JST 0.031
BTC 60327.71
ETH 2568.97
USDT 1.00
SBD 2.57