A simple lottery contract that awards a lucky winner with a minted nft and half of the generated prizepot.
Check operator section for how to operate lottery.
This boilerplate uses the following tech stack:
- React - A JavaScript library for building user interfaces.
- use-Contractkit - A frontend library for interacting with the Celo blockchain.
- Hardhat - A tool for writing and deploying smart contracts.
- Bootstrap - A CSS framework that provides responsive, mobile-first layouts.
To get this project up running locally, follow these simple steps:
git clone https://github.com/JoE11-y/NFT-Lottery-Frontend.git
cd NFT-Lottery-Frontend
npm install
npm start
To properly test the dapp you will need to have a Celo wallet with testnet tokens. This learning module NFT Contract Development with Hardhat will walk you through the process of creating a Metamask wallet and claiming Alfajores testnet tokens.
npx hardhat compile
npx hardhat test
- Create a file in the root directory called ".env"
- Create a key called ACCOUNT_KEY and paste in your private key. e.g
ACCONT_KEY = "...";
You can find more details about the whole process in the Dacade NFT Contract Development with Hardhat learning module. It will also show you how to get testnet tokens for your account so you can deploy your smart contract in the next step.
npx hardhat run --network alfajores scripts/deploy.js
This command will update the src/contract files with the deployed smart contract ABI and contract address.
This section contains node-js terminal scripts to be run to control the operation of the lottery.
node ./operator/setOperator.js --operatorAddress {your address}
This command is the first command that should be run after deploying the contract, it sets the operator address giving that address access to functions like starting the lottery and other admin restricted functions.
node ./operator/startLottery.js
This command will start a new lottery session
node ./operator/getWinningTickets.js
This command gets the winning the ticket for that lottery session, can be only ran once the current lottery session time range has been exhausted.
node ./operator/payoutWinner.js
This command pays out the winner, after the winning ticket has been gotten. The function also sets the lottery state to idle, meaning a new lottery session can be started.
node ./operator/withdrawContractFunds.js
This command allows the lottery owner to be able to withdraw his own winnings from the lottery, function can only be called after the has been paid off.
node ./operator/updateLotteryInterval.js --interval {interval} --timeUnit {timeUnit}
-
This command allows the operator to be change the lottery interval, i.e. how long a lottery session can last.
-
The value for interval can only be a number/integer, while for the timeUnit can only be in the string format and the accepted values are (seconds, minutes, hours, days and weeks) any other format will result in function failure.
A much better implementation would be to use either oracles or a collab with chainlink to use their keeper service for contract automation