-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
28,507 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ALCHEMY_API_KEY= | ||
ROPSTEN_PRIVATE_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
node_modules | ||
.env | ||
|
||
#Hardhat files | ||
cache | ||
artifacts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity >=0.7.0; | ||
|
||
import "@openzeppelin/contracts/access/Ownable.sol"; | ||
import "hardhat/console.sol"; | ||
|
||
contract Lottery is Ownable { | ||
uint256 public constant minParticipants = 2; | ||
uint256 public constant maxParticipants = 10; | ||
|
||
address payable[] public participants; | ||
address payable public lastWinner; | ||
|
||
function participate() external payable { | ||
require(msg.value == 0.1 ether, "ticket cost is 0.1 eth"); // 0.1 eth | ||
require( | ||
participants.length < maxParticipants, | ||
"max participants reached for this round" | ||
); | ||
|
||
participants.push(payable(msg.sender)); | ||
} | ||
|
||
function execute() external onlyOwner { | ||
require( | ||
participants.length >= minParticipants, | ||
"need more participants" | ||
); | ||
|
||
uint256 randomNumber = uint256(keccak256(abi.encode(block.timestamp))); | ||
uint256 winnerIndex = randomNumber % participants.length; | ||
lastWinner = participants[winnerIndex]; | ||
lastWinner.transfer(address(this).balance); | ||
delete participants; | ||
} | ||
|
||
function participantsCount() external view returns (uint256) { | ||
return participants.length; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { task } from "hardhat/config"; | ||
import "@nomiclabs/hardhat-waffle"; | ||
|
||
import dotenv from 'dotenv' | ||
dotenv.config() | ||
|
||
// This is a sample Hardhat task. To learn how to create your own go to | ||
// https://hardhat.org/guides/create-task.html | ||
task("accounts", "Prints the list of accounts", async (args, hre) => { | ||
const accounts = await hre.ethers.getSigners(); | ||
|
||
for (const account of accounts) { | ||
console.log(await account.address); | ||
} | ||
}); | ||
|
||
// You need to export an object to set up your config | ||
// Go to https://hardhat.org/config/ to learn more | ||
|
||
export default { | ||
solidity: "0.8.7", | ||
networks: { | ||
ropsten: { | ||
url: `https://eth-ropsten.alchemyapi.io/v2/${process.env.ALCHEMY_API_KEY}`, | ||
accounts: [`0x${process.env.ROPSTEN_PRIVATE_KEY}`], | ||
}, | ||
}, | ||
}; |
Oops, something went wrong.