This repository contains two projects: lottery and lottery-react. The lottery project includes the smart contract written in Solidity, and the lottery-react project is a React application that interacts with the smart contract.
- Solidity
The Lottery smart contract allows participants to enter the lottery by sending a minimum amount of Ether. The manager can pick a random winner, and the contract transfers the balance to the chosen winner. Only the manager is allowed to initiate the winner-picking process.
enter(): Allows participants to enter the lottery by sending a minimum amount of Ether.random(): Generates a pseudo-random number using block information and current players.pickWinner(): Allows the manager to pick a random winner and transfer the balance to them.getPlayers(): Retrieves the list of current participants.
- JavaScript (React)
The lottery-react project is a React application that provides a user interface for interacting with the Lottery smart contract.
App: The main component that displays information about the lottery, allows users to enter the lottery, and enables the manager to pick a winner.- Other components (e.g., form elements) as needed.
The React app uses the web3 library to connect to the Ethereum blockchain. The web3 instance is created using the HDWalletProvider and is used to deploy the smart contract, fetch contract details, and interact with its functions.
The smart contract is deployed using the HDWalletProvider and Truffle's web3 library. The deployment script is found in lottery at deploy.js.
- Clone this repository.
- Install dependencies for each project (
lotteryandlottery-react). - Configure environment variables (e.g., Infura URL, mnemonic phrase) for deploying and interacting with the smart contract.
- Deploy the smart contract using the deployment script in
lottery. - Run the React app using
npm startin thelottery-reactproject. - Interact with the lottery by entering and picking winners.
Feel free to explore each project's folder for more details.
This project was inspired by Stephen Grider's Ethereum and Solidity: The Complete Developer's Guide course on Udemy. The course provided valuable insights into smart contract development on the Ethereum blockchain. While this project shares similarities with the course content, it has been independently developed and customized for learning purposes.