What If You Could Win More Money Through The Lottery?
In this article, I’m not giving you some extraordinary mathematical way to make money through the lottery. What I’m introducing is a new system. A system that will be more cost-efficient than the current one. But first, you have to understand why the current system sucks.
Current lottery system
The lottery is centralised, like most things in our world. Everything goes through one company.
Imagine you’re this company. You’re selling a piece of paper to your customers and they pay you 100 times more for it than it costs to produce it. That sounds like a great business model. The only catch is, you will need to give a percentage away to the public so that they can win something.
The more money you make, the more you can give away, which attracts even more people and then you will make even more money.
Fun cycle right? An infinite money loop. Sadly, you and I are probably not on the right end of that cycle, since we’re not the owner of that company. So no money for us…
Or is there?
I present a decentralised lottery system!
Decentralised lottery system
How do we make the current system decentralised? By adding the fancy word blockchain to it. Okay, it isn’t that easy but it does have to do with blockchain, the king of making centralised stuff decentralised.
If you have no clue what blockchain, smart contracts or De-Fi is, then I’d highly recommend you to read my previous articles on those topics.
What Is Blockchain And Will It Replace The Internet?
I’ll explain what blockchain is, where it’s used and if it’s able to replace the internet!
Why Bankers Should Sh*t Themselves
Yes, you read that right. Banks should be scared. They’ve got competition and they’re ready to rumble!
So what’s the difference between a decentralised lottery system and a centralised lottery system?
Well, there is no one taking huge cuts from the lottery pot. The huge cut, that’s taken at a centralised system, isn’t only the profit for the owner, but also all the expenses. Imagine how many employees they have to pay, how many machines they have to invest in to produce all those tickets, with how many stores they had to cut a deal to be able to have them sell their lottery tickets.
It’s an inefficient way to do business, but there hasn’t been any other way to do it, until now.
Thanks to smart contracts we’re able to build our own lottery system. One where everyone can see the code you wrote and clarify that no one is taking any cuts. And if someone is, you can see that and see how much it is. All of it is transparent and honest.
And it isn’t that hard to make one!
My semi-decentralised lottery system
I built my own semi-decentralised smart contract lottery. It’s semi because there’s still one person who decides when the lottery starts and ends. I haven’t deployed it to the real blockchain yet and probably never will. But if you want to see the code for it, you can check it out on my GitHub repository below.
GitHub - tikkanenfelix/Lottery:
Semi decentralised lottery system built using Solidity, for the smart contract itself, and python, for the deployment and testing of that contract.
I built it for the Etherium blockchain using solidity as the language for my smart contract.
It’s also a lot easier to use. The only thing you need to do to enter is to pay the entry fee to the smart contract. That’s it!
Here’s how it works.
- Owner starts it
- Players enter by depositing $50 into the lottery smart contract
- Owner ends it
- A random player gets chosen and all the funds are deposited into their account immediately
First, the owner of this smart contract will have to start the lottery. Then the players can enter it.
But how can only the owner start the smart contract?
Openzeppelin has created an onlyOwner modifier. So when I add this modifier to the start function of the lottery, I will be the only person who can start the lottery, since I launched the lottery.
You have to pay $50 in ETH to enter this lottery. But since the price of Etherium keeps fluctuating, I have to make live conversions between USD and ETH.
The good thing about the transparency of blockchain technology is, you only need to build everything once. If blockchain was like the internet, and I wanted this feature on my website, I would’ve had to build it from scratch, or hire someone. That’s very inefficient.
So instead of building it from scratch, I used the ethUsdPriceFeed smart contract from chainlink.
Now the smart contract needs to add a little bit of extra ETH to the $50. Not much, it’ll cost virtually nothing. Why does it need it then? Well, that's the transaction fee to be able to put that information on the blockchain. That will be the only cost of this lottery system. Literally, nothing compared to the current one.
Once the transaction has gone through, then you wait until the owner has decided that enough players have entered.
Then the owner will end the lottery, which will pick a random winner out of the list of players. The tricky thing about this part is, the smart contract needs to pick the players randomly. But code is a deterministic system, just like math, 1+1 will always be 2.
So how can it pick a random number?
It might be hard to understand why randomness is so hard, I mean you just google random number generator and voila! You have a random number, or do you?
What you actually have is a pseudorandom number. Google takes some values from stuff like your cookies, ram used, history, cursor placement, etc and throws that into an algorithm, which shoots out a number based on those values.
A very simple example:
Number of cookies used: 12
Amount of GB of ram used: 3
Cursor distance from the left side of the screen in cm: 5
The algorithm: (12+3)/5
The random number: 3
If something like this would’ve been the algorithm then the winner of the lottery would be the third person who entered. Because the output of the random number generator was 3.
This kind of algorithm is not perfect, since it can be manipulated. So for a lottery system where a lot of money is involved, that’s not viable. People could manipulate this to their advantage and make themselves always win. This has already happened to a lot of smart contracts.
But even if you could find a truly random algorithm, you still can’t use that on the blockchain. The blockchain is a consensus mechanism. All the nodes, or participants, need to come to a consensus about the matter that goes onto the blockchain. But if the chosen number is truly random then all of the nodes will propose another number, so no one will ever agree to one.
Where then can you find true randomness? Crypto coins? The charts look very random and squiggly. Just like the stock market. No one knows if it goes up or down.
The only place where you can find true randomness is in the real world. Luckily there is one company that combines the real world with blockchain, Chainlink. Yes, the same company who made the ethUsdPriceFeed contract. Very simply said, they take data from the real world and put it on the blockchain. If you want to know exactly how they do that, click here.
So they made a smart contract called the VRF Coordinator. Which outputs a verifiable random number. Very useful for us, we can use someone else’s work again to make something new.
The owner can then end the lottery and a random winner is chosen. They will receive all the money that was sent to the smart contract.
However, there is a downside to this system. If there is a vulnerability in the code, a hacker can then take all the money from the smart contract. And since we can’t update smart contacts like apps on our phones, it is very hard to patch any vulnerabilities. The smart contract will just have to be perfect.
This kind of implication of De-Fi is very interesting. At this moment in time, the kings of gambling are casinos. A lot of money to be made there since the house always wins. Crypto casinos are already becoming a thing.
Here are a few examples if you’re interested.
Best Bitcoin Casinos " Find The Best Crypto Casino (2021)
With cryptocurrencies and blockchain, in general, growing rapidly, and Bitcoin being at the forefront of this movement…
If you lose all your money thanks to these games, it’s not my fault :)
This does however have some real-world consequences, of course. One of them obviously is, the middleman gets cut out from this profitable business. Some smaller businesses rely on the sale of lottery tickets. They can’t survive without it.
For example, small shops, if they get cut out they probably won’t survive. And then on a Sunday night when you need that snack for your Netflix and chill session, everything is closed except those small shops. But because of this technology, they went bankrupt.