Challenge 🏆
- 🏆 The Natives track and Lottery functionality bonus challenge by HAPI.one on the NEAR MetaBUILD Hackathon
What is LotteRhino? 🦏
🦏 LotteRhino is a decentralized lottery platform with daily draws and jackpot based on solidity written smart contract.
Inspiration 💡
🎫 There were a lot of interesting bonus challenges, but the lottery functionality seemed challenging. We are already familiar with blockchain terms and environment, but we have never ever made NFTs. Since we like to learn, this seemed a proper choice. We want to know what is the difference between a classic ERC20 token and an NFT. The topic is also funny. In elementary school a school-level event (like carnival) we usually played a lottery game. Each participant got a ticket at the entrance. At the end of the evening a student pulled the winning numbers from a hat. If somebody had the exact number on their own paper, they won. During the development we lived through those experiences again.
🔗 There are free or paid lottery platforms for blockchains on the internet. If somebody wants to run an online casino or lottery platform, they can choose from a lot of various solutions. However, all of them have their own limitations. We want to create not just raw code, but a working demo as well. This demonstrates how anybody can use our smart contract. The UI and the code work independently, any of them can be changed any time to fit a new network or new needs of users.
What it does ❓
🤑 LotteRhino provides daily lottery drawings and jackpot drawings. If the number of tickets is under 100, there is only 1 winner to provide a higher prize. When the number of tickets is over 100, the number of winners is between 10 and 20 based on a pseudo-random number. The 90% of income goes to the prize pool and the remaining part is for the costs of maintenance. The chance of drawing a jackpot is 1:100, which is pretty high compared to other lottery systems.
How does it work? ⚙
Users can make 6 different actions: 1️⃣ buying new tickets for themselves 2️⃣ buying tickets for others as a gift 3️⃣ drawing a lottery 4️⃣ querying their own balance 5️⃣ listing their own lottery tickets 6️⃣ withdrawing the prize
🦏 For playing LotteRhino, you should have an Aurora Wallet with Metamask. You can buy unlimited tickets during the collecting phase if you pay the price of tickets. The timer shows the remaining time from the collecting phase. The lottery rounds are daily. After 12:00 am (midnight) GMT the collecting phase switched to the drawing phase. Any user can call the draw function.
🧐 Buying a ticket does not guarantee a win. More tickets mean more chances. However, a distinct user can win daily only once.
😄 When the number of tickets bought is under 100, there is only one winner. Above 100, the number of winners is between 10 and 20. During the draw phase the smart contract generates a random number to decide the exact number of winners. If the number of winners is under 20, the remaining pool goes to the jackpot prize pool.
🎠 After the common drawing circle, the smart contract deals the jackpot. The chance of drawing the jackpot is 1:100. If there is no jackpot drawing, the prize pool increases.
🎁 You can withdraw your prizes any time. If you want, you can buy a ticket for someone else as a gift. If the gift ticket wins, the prize belongs to the recipient not the buyer.
♻ After the drawing phase, a new collection phase begins. Each lottery ticket is a unique, nonfungible NFT. If you buy a ticket, it belongs to your account forever. However, a ticket is valid for one drawing round. If you want to be part of a new drawing the next day, you have to buy a new ticket or tickets.
How we built it 🔨
🖋 The smart contract is written in solidity. We used VSCode and Remix.
😵 The solidity code uses pragma ^0.8.0 and it is compiled with the default complirres of Remix. It was an interesting experience, that the same contract sometimes failed to deploy to the testnet and a couple of minutes later the same build did not fail.
💻 The UI was built in HTML, CSS and JavaScript. The JS have more 3rd party components, Big.JS and Ethers.JS are blockchain related. We built a dummy api for the case when the user doesn’t have MetaMask installed or anything else that provides the ethereum functionality. The PHP mocks the getUIRecord endpoint of the smart contract with random dummy data.
➕ In the near future minor improvements are needed, since calculating percentages require safe math checks. They are pulled out from the final code due to spare gas.
Challenges we ran into 💪
⛽ Deploying a working smart contract can be tricky due to a lot of unexpected events from errors in faucet collecting till running out of gas. The last type of errors motivated us to refine our code to run smoother.
📐 It was hard to figure out how to fit the limitations of Solidity and low gas at the same time. The hardest problem was to avoid arrays in storage structs. However simple arrays like an array of addresses can get initialized in a storage struct, more complex ones, which contain other struct cannot. This is a really sad thing. However there are a lot of workarounds which were marked as good solutions, in fact they don’t work on the actual versions or they are too complicated in bigger smart contracts like our one. At the end we managed it with helper arrays and custom workarounds but this challenge endangered the readiness of our whole project.
🥊 Now we know that we have to prepare ourselves for even more barriers than we could expect.
Accomplishments that we're proud of 😎
💰 This idea has real business impact. We tried to meet the different needs of users: winning regularly and winning big prizes. That’s why we introduce a jackpot besides the daily draws. In the future we want to widen the service and maintain a referrer system to bring more new users into the service.
🧩 We made a working proof of concept and deployed it on Aurora Testnet.
🔩 The logic is clear behind the idea and the smart contract runs smoothly.
What we learned 📘
📘 How to create NFTs and a lottery game
📘 How to generate pseudo-random numbers in smart contracts
📘 How to optimize a solidity code
📗 Rhinos are mammals. 🤣
What's next for LotteRhino ⏱
🚀 The next step is going to the mainnet. After that we want to accept multiple coins. From the scope of functionality, in the future we want to introduce a referrer system to increase the number of players. We want to add more different lotteries and special bonuses to widen the service.
Built With
- css3
- html5
- javascript
- remix
- solidity
- vscode

Log in or sign up for Devpost to join the conversation.