As part of Code collision Hackathon and Encode's Aptos bootcamp, the team (Dennis, Aashish and Akshar) worked on the project: Aptos Lottery. This project implements a decentralized lottery system on the Aptos blockchain using the Move programming language. The smart contract allows users to participate in a lottery by buying tickets with AptosCoin, and uses on-chain randomness to select a winner.
- Ticket Purchase: Users can buy lottery tickets using AptosCoin.
- Random Winner Selection and Payout: Utilizes Aptos' on-chain randomness module for fair winner selection and pays out the prize to the winner in same transaction.
- View Functions: Provides functions to check lottery status, prize amount, and participant count.
- Blockchain: Aptos
- Smart Contract: Move
- Frontend: Next.js, React, TypeScript
- Styling: Tailwind CSS
- State Management: React Query
- Wallet Integration: Aptos Wallet Adapter
- Node.js (v14 or later)
- Yarn or npm
- Aptos CLI (for contract deployment)
- An Aptos wallet (e.g., Petra, Martian)
-
Clone the repository:
git clone https://github.com/your-username/aptos-lottery.git cd aptos-lottery
-
Install dependencies:
cd frontend yarn install
-
Set up environment variables: Create a
.env.local
file in thefrontend
directory and add the following:NEXT_PUBLIC_APP_NETWORK=testnet NEXT_PUBLIC_MODULE_ADDRESS=your_module_address NEXT_PUBLIC_ADMIN_ADDRESS=your_admin_address
-
Start the development server:
yarn dev
-
Open http://localhost:3000 in your browser to see the application.
- Navigate to the
move
directory. - Update the
Move.toml
file with your account address. - Compile and deploy the contract using Aptos CLI:
aptos move compile aptos move publish
- Connect your Aptos wallet to the application.
- As an admin, create new lotteries with specified durations.
- Users can buy tickets for active lotteries.
- When a lottery ends, the admin can draw a winner.
- Winners are automatically credited with the prize amount.
move/
: Contains the Move smart contractfrontend/
: Next.js frontend applicationsrc/components/
: React componentssrc/view-functions/
: Functions to interact with the smart contractsrc/entry-functions/
: Functions to call smart contract entry pointssrc/constants/
: Configuration constantssrc/utils/
: Utility functions
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.