Skip to content

mp-web3/nextjs-smartcontract-lottery

Repository files navigation

Next.js Smart Contract Lottery

This project is a decentralized application (DApp) built with Next.js and Solidity. It allows users to participate in a lottery where a winner is picked randomly using Chainlink VRF (Verifiable Random Function).

Table of Contents

  1. Deployments
  2. Access the Website hosted on IPFS
  3. Installation
  4. Usage
  5. Features
  6. Technologies Used
  7. Deploy
  8. Contributing
  9. License

Deployments

Deployed using only IPFS Desktop:

To see the website directly on IPFS, you need to have IPFS Desktop running or a local IPFS node enabled.

Access the Website hosted on IPFS

Brave

You can simply use the Brave IPFS node or install the IPFS Companion Extension.

Google Chrome

Install the IPFS Companion Extension from the Chrome Web Store.

Firefox

Install the IPFS Companion Extension from Firefox Browser ADD-ONS.

Other Browsers

Read the IPFS Companion Install Documentation to install the IPFS Companion on your preferred browser.

Installation

To set up the project locally, follow these steps:

  1. Clone the repository:

    git clone https://github.com/your-username/nextjs-smartcontract-lottery.git
    cd nextjs-smartcontract-lottery
  2. Install dependencies:

    yarn install
  3. Spin Up hardhat node

    hardhat is not installed in this repository

    So you must do one of the following:

    Now run

    hardhat node
  4. Run the development server:

    yarn dev

    Open http://localhost:3000 with your browser to see the result.

Usage

  • Connect Wallet: Click on the "Connect Wallet" button to connect your Ethereum wallet.
  • Switch Network: If you are not on the Sepolia network, you will be prompted to switch.
  • Enter Lottery: Enter the lottery by paying the entrance fee.
  • Check Winner: The winner is picked randomly using Chainlink VRF.

Features

  • Decentralized Lottery: Participate in a fair and transparent lottery.
  • Chainlink VRF: Ensures the randomness of the winner selection.
  • Wallet Integration: Connect your Ethereum wallet to interact with the DApp.
  • Network Switching: Automatically prompts the user to switch to the Sepolia network if not already connected.

Technologies Used

  • Next.js: React framework for server-side rendering and static site generation.
  • Solidity: Programming language for writing smart contracts.
  • Chainlink VRF: Verifiable Random Function for generating random numbers.
  • Web3uikit: UI components for Web3 applications.
  • Moralis: Simplifies interaction with blockchain data.

Deploy

Deploy on IPFS

Requirements

  • IPFS Desktop

To install the correct version of IPFS Desktop, please read the docs Install the IPFS Desktop App.

Deploy

From the root repository (nextjs-smartcontract-lottery), run in the terminal:

yarn build

This will automatically export the static version of the website in the newly created "out" directory.

Check out Next.js documentation for Static Exports to learn more.

Now:

  • Open IPFS Desktop
  • Click the "FILES" tab on the right
  • Click the Import Button
  • Select the "out" directory created after running yarn build

Congrats! Now your website is officially hosted on IPFS

IPFS Desktop Import

Check out your website on your favorite browser!

In IPFS Desktop, Files Tab:

  • Click the three dots on the right of the "out" directory
  • Click on "Copy CID"
  • Open your preferred browser
  • Paste the CID preceded by "ipfs://"

Deploy on IPFS through Fleek

Deploying on Fleek is easier and helps other nodes pinning our Website. Fleek deploys both on IPFS and on regular hosting.

  • Navigate to Fleek
  • Sign up with your wallet
  • Click on "Deploy your Site"
  • Click on "Add New" -> "Deploy my site"
  • Click on GitHub, after authorizing you will be prompted to install "Fleek" on GitHub, do it
  • Now select the cloned "nextjs-smartcontract-lottery" repository
  • Click on "Deploy"

Fleek Deploy

Now just wait for the deployment to finish.

Contributing

Contributions are welcome! Please follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature-branch).
  3. Make your changes.
  4. Commit your changes (git commit -m 'Add some feature').
  5. Push to the branch (git push origin feature-branch).
  6. Open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published