https://github.com/cgrade/raffle_contract
Raffle is a decentralized application that allows users to participate in a raffle and randomly selects a winner. The contract utilizes Chainlink VRF (Verifiable Random Function) for secure random number generation, ensuring fairness in the selection process.
https://github.com/cgrade/raffle_contract
chainlink ethereum-contract foundry smart-contracts solidity vrfcoordinator
Last synced: 7 days ago
JSON representation
Raffle is a decentralized application that allows users to participate in a raffle and randomly selects a winner. The contract utilizes Chainlink VRF (Verifiable Random Function) for secure random number generation, ensuring fairness in the selection process.
- Host: GitHub
- URL: https://github.com/cgrade/raffle_contract
- Owner: cgrade
- Created: 2024-08-15T12:52:23.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-11-10T08:17:39.000Z (over 1 year ago)
- Last Synced: 2025-01-10T01:52:17.777Z (over 1 year ago)
- Topics: chainlink, ethereum-contract, foundry, smart-contracts, solidity, vrfcoordinator
- Language: Solidity
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Raffle Smart Contract
## Overview
**Raffle** is a decentralized application that allows users to participate in a raffle and randomly selects a winner. The contract utilizes Chainlink VRF (Verifiable Random Function) for secure random number generation, ensuring fairness in the selection process.
## Features
- Users can enter the raffle by sending ETH.
- A winner is randomly selected after a specified time interval.
- The contract emits events for significant actions, such as entering the raffle and selecting a winner.
- Implements Chainlink VRF for secure and verifiable randomness.
## Smart Contracts
### 1. Raffle.sol
- **Description**: The main contract that manages the raffle process.
- **Key Functions**:
- `enterRaffle()`: Allows users to enter the raffle by sending ETH.
- `checkUpkeep()`: Checks if the conditions are met to pick a winner.
- `performUpkeep()`: Performs the upkeep to select a winner.
- `fulfillRandomWords()`: Callback function called by Chainlink VRF to fulfill the random number request.
- `getEntranceFee()`: Returns the entrance fee for the raffle.
- `getRaffleState()`: Returns the current state of the raffle.
- `getPlayer(uint256 index)`: Returns the address of a player at a specific index.
### 2. DeployRaffle.s.sol
- **Description**: A script for deploying the Raffle contract.
- **Key Functions**:
- `run()`: Deploys the Raffle contract and sets up the necessary configurations.
### 3. HelperConfig.s.sol
- **Description**: A helper contract that manages network configurations and settings.
- **Key Functions**:
- `getConfig()`: Returns the configuration for the current network.
- `setConfig()`: Sets the configuration for a specific network.
### 4. LinkToken.sol
- **Description**: A mock ERC20 token contract for LINK, used in the raffle.
- **Key Functions**:
- `mint()`: Mints new tokens to a specified address.
- `transferAndCall()`: Transfers tokens to a contract address and calls a function on the recipient.
### 5. RaffleTest.t.sol
- **Description**: Unit tests for the Raffle contract.
- **Key Tests**:
- Tests for entering the raffle, checking upkeep, performing upkeep, and fulfilling random words.
## Installation
To install the necessary dependencies, run:
```shell
$ forge install
```
## Usage
### Build
```shell
$ forge build
```
### Test
```shell
$ forge test
```
### Deploy
To deploy the contracts, use the following command:
```shell
$ forge script script/DeployRaffle.s.sol:DeployRaffle --rpc-url --private-key
```
## Contributing
If you would like to contribute to this project, please fork the repository and submit a pull request.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.