This Ethereum smart contract facilitates a decentralized lottery system. Participants can enter the lottery using ERC20 tokens, and the system automatically selects winners after each 10-minute interval. If the interval exceeds, the next participant to buy a ticket will trigger the lottery result announcement for the previous session and will be rewarded for this action.
- Support for Multiple ERC20 Tokens: Participants can enter the lottery with any ERC20 token supported by the contract.
- Automated and Timed Draws: Lottery draws are intended to occur every 10 minutes. If a draw is overdue, the next ticket purchase triggers the draw and rewards the purchaser for announcing the result.
- Social Cause Contribution: 50% of the lottery proceeds are dedicated to social causes.
- Rewards for Participants: Besides the lottery winnings, participants receive native tokens as a bonus for their participation. Additionally, the individual who triggers an overdue lottery result announcement is rewarded, acknowledging the gas cost associated with this task.
- Node.js and npm must be installed.
- Truffle Framework should be set up for deploying and managing smart contracts.
- An Ethereum wallet with some ETH for contract deployment and interaction.
-
Clone the repository and navigate into the project directory:
git clone <repository_url> cd <project_directory>
-
Install required npm dependencies:
npm install
-
Create a .env file in the project root. Add your Ethereum wallet's private key and your Infura API key:
PRIVATE_KEY=<your_private_key> INFURA_API_KEY=<your_infura_api_key>
-
Compile the smart contracts:
truffle compile
-
Compile the smart contracts:
truffle migrate --network rinkeby
Approve the smart contract to spend the ERC20 tokens you want to use for buying lottery tickets. Then, call buyLottery(address token)
to purchase your ticket. If the current lottery time has exceeded 10 minutes, this action will also trigger the announcement of the previous lottery's results, and you will receive a reward for this.
You can call getDetails(address token, uint256 lotteryNumber)
to retrieve details about any lottery session, such as the total fund, number of participants, and the start time.
getTotalTokenCount()
: Returns the total number of distinct tokens used in the lotteries.getToken(uint256 number)
: Retrieves the address of a specific token by its index.getCurrentLotteryNumber(address token)
: Fetches the latest lottery session number for a given token.
Contributions to improve the contract or its documentation are welcome. Please feel free to open issues, submit pull requests, or suggest features.
This project is licensed under the MIT License - see the LICENSE file for details.