Giter Club home page Giter Club logo

nft-giveaway's Introduction

Contributors Forks Stargazers Issues MIT License LinkedIn codecov

NFT Giveaway

A giveaway smart contract where anyone can join in to have a fair chance at winning an awesome NFT
Explore the docs »
Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Roadmap
  4. Contributing
  5. License
  6. Contact

About The Project

Giveaways are a form of expression of love of creators/influencers towards their community and supporters. Hundreds of giveaways occur every month, and thousands of people join in to have a shot at getting a console, PC, movie tickets, a pair of those shining new sneakers and what not.

Making the process of selecting a winner for the giveaway decentralized and devoid of any tampering is a difficult task. That's where the blockchain technology comes to the rescue! Using smart contracts and Chainlink's VRF service, which provides verifiable random numbers, we can pick a truly random winner. Everything is carried out on-chain with smart contracts - entering the giveaway, picking a winner, and even sending him/her the prize!

When the winner is selected, an NFT (Non-Fungible Token) is minted to the winner. The NFT can itself be a prize (a collectible), but can also be representative of physical assets - such as a pair of sneakers - and hold information about its current state in its metadata! The winner gets two prizes: first, their sneakers, and second, the NFT! The NFT can even be burnt after the winner gets the sneakers delivered to them, ensuring that the prize was claimed successfully.

This project allows anyone to configure and create a giveaway of their own on EVM compatible chains. Though this project is well tested and documented, it hasn't been audited yet, so please don't deploy it on the mainnet! Keep your giveaways restricted to testnets only.

If you want to see the full list of the giveaway smart contract's functions and their descriptions, navigate to ./docs/index.html. Open the index.html page in a browser to view the documentation.

Additionally, you can view the most recent deployment of the giveaway smart contract here.

Built With

  • Hardhat
  • JavaScript
  • Solidity
  • Ethereum
  • npm

Getting Started

Prerequisites

Make sure you have node.js and git installed and configured on your system. Also, you need to have a MetaMask account with sufficient ETH, and LINK tokens. If you are using the Sepolia testnet, you can get Sepolia testnet ETH from Alchemy and LINK tokens from Chainlink faucet. Try to get about 3-4 ETH, and 12 LINK tokens.

Installation

Clone this repository

git clone https://github.com/mgnfy-view/nft-giveaway.git

Cd into the project folder and install the dependencies

cd nft-giveaway
npm install

Setup, Deployment and Cleanup

Warning

The contracts haven't been audited yet, so please keep your deployments restricted to testnets only!

Depending on the test network you want to deploy the giveaway to, you'll need the following values:

  • RPC URL: you can get this from Alchemy or Infura for any of your preferred chain
  • Private key for one of your accounts: create your MetaMask wallet and get your private key from there. This private key will be used to deploy the contract and fund it with LINK tokens. Ensure that it has enough ETH and LINK tokens
  • NFT metadata hash: you'll need to upload your NFT metadata to IPFS and get its hash
  • Etherscan and CoinMarketCap api keys: optionally, you can get the etherscan api key and coinmarketcap api key. The former will let you verify contracts on etherscan, and the latter will provide you with gas reports with gas consumed mentioned in your preferred currency that you may set in the hardhat.config.js file's gasReport section.

Set these values correctly in the .env.example file in the top level of the project, and rename the file to .env, and bring them in your hardhat.config.js file. An example configuration for the Sepolia testnet is given in the same file.

You'll also need to configure the helper.config.js file. Make sure you have the ID of the chain you're deploying to. In the networkConfig object in helper.config.js, add the blockchain's ID as the key, and add the object containing configuration details as the value. You'll need:

  • name: name of the chain
  • blockConfirmations: the number of blocks you want to wait during deployment (6 is generally a good number)
  • keyHash: the amount of gas you want to spend on each random word request
  • callbackGasLimit: the maximum gas limit for fulfillRandomWords function
  • interval: the time in seconds after which to pick a winner
  • vrfCoordinatorAddress: the address of Chainlink's VRFCoordinator for your preferred chain
  • linkTokenAddress: the address of the LINK token contract for your preferred chain
  • upkeepContractAddress: the address of the Chainlink registrar for your preferred chain
  • fundLinkAmountForSubscription: the amount of LINK tokens to fund the subscription ID which is dynamically created by the contract on deployment
  • fundLinkAmountForUpkeep: the amount of LINK tokens to fund the upkeep

An example configuration for the Sepolia testnet (ID: 11155111) is given in the helper.config.js file. You can get more details about these values at Chainlink VRF docs and Chainlink Automation docs.

After you have configured the helper.config.js and hardhat.config.js files, deploy the giveaway contract

npx hardhat run scripts/deploy.js --network <network-name>

The contract will create a subscription and add itself as a consumer. The deployment script will fund the subscription and the upkeep. Sit back, relax, and watch.

That's it. The giveaway should be up and running, and people can join in! Wait to find out who's the winner!

After the giveaway has ended, you can use the removeGiveawayFromConsumers(), cancelSubscription(), and withdraw() methods to clean up and claim the unused LINK tokens. You can use the cleanup task for that:

npx hardhat cleanup --address "YOUR_DEPLOYED_GIVEAWAY'S_ADDRESS" --network <network-name>

Roadmap

  • Write the NFT smart contract
  • Write the giveaway smart Contract
  • Write the deployment script
  • Carry out unit testing
  • Deploy the giveaway contract on the Sepolia testnet
  • Write documentation and generate docs
  • Write a good README.md

See the open issues for a full list of proposed features (and known issues).

Contributing

Check out CONTRIBUTING.md for contribution guidelines.

License

Distributed under the MIT License. See LICENSE.txt for more information.

Reach Out

Here's a gateway to all my socials, don't forget to hit me up!

Linktree

nft-giveaway's People

Contributors

mgnfy-view avatar

Stargazers

 avatar

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.