Giter Site home page Giter Site logo

3squ4red / lottery-dapp Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 261 KB

A Lottery dApp built on Goerli testnet using Hardhat, ether.js and Next.js

Home Page: https://lottery-dapp-bytecode-velocity.vercel.app/

JavaScript 77.25% Solidity 18.99% CSS 3.76%
dapp ethereum solidity

lottery-dapp's Introduction

Ether Lottery

A simple Lottery dApp built on Goerli testnet, whose winner selection method is based on a provably fair and verifiable random number generator.

Rules

Participation

  • Exactly 0.01 ETH must be sent to participate in the lottery
    • Any different amount would revert the transaction
    • The same participant can however click Participate again to place more bet than just 0.01 ETH
  • The manager cannot participate
  • You cannot participate if the manager is the zero-address. This could happen after a lottery ends

Getting the results

  • Only the manager can get the results
  • Lottery must have at least 3 participants
  • The manager must not be a zero-address

Setting a new manager

  • A lottery must have ended and the current manager should be a zero-address

Please make sure to connect your MetaMask wallet and switch to Rinkeby Testnet before clicking any of the three buttons to avoid seeing big red error messages. Support for other wallets have not been implemented yet.

Demo ๐Ÿš€

Try it out here and view the lottery contract here

Tech Stack

The frontend is built using Next.js and Bulma library for CSS styling.

On the Web3 side, the contract is written in Solidity and compiled and deployed using Hardhat. The contract uses Chainlink VRF to generate a random numbers for the selection of a winner. This VRF however, *doesn't return a random number immediately* and takes upto 2 minutes to do so, which is why after clicking the *Get Results* button, a 120 seconds timer starts, to show the time remaining.

Limitations

The most prominent limitation of this Lottery system is that it's proper functioning is heavily dependent on how it's going to be interacted with. The buttons are not turned off (i.e. made un-clickable) at any moment. So, if a participant decides to just go ahead and randomly start clicking the buttons in between transactions, the application is mostly likely going to report an error or even worse, it may crash. Therefore, if you'll try it using your own sincere conscience and patiently wait for the operations to complete and the updates to appear on screen, you could have a good time with this little creation of mine.

The contract is manually tested using Remix IDE and it's local accounts but not with any testing framworks or libraries.

What I learned

I came across many new findings which I may have remained unaware of without creating this decentralized application. Some of them are:

  • How to use an oracle like Chainlink VRF
  • Knowledge of Solidity and Ethereum alone is not enough to build a fully functional dApp
    • Frontend designing skills probably comes first
  • How to host my own Next.js project for free on Vercel
  • Interacting with MetaMask wallet using Ether.js
  • Importance of using enviroment variables
  • Unit conversion using utils library of Ether.js

Contact me

Instagram | Telegram | Twitter | Email

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.