Updated Correct v2.5 VRF
This commit is contained in:
parent
5a5063948c
commit
7ecbd4c7b5
@ -0,0 +1,12 @@
|
||||
node_modules
|
||||
artifacts
|
||||
cache
|
||||
coverage*
|
||||
gasReporterOutput.json
|
||||
package.json
|
||||
img
|
||||
.env
|
||||
.*
|
||||
README.md
|
||||
coverage.json
|
||||
deployments
|
80
contracts/Raffle.sol
Normal file
80
contracts/Raffle.sol
Normal file
@ -0,0 +1,80 @@
|
||||
// SPDX-License-Identifier: Unlicense
|
||||
|
||||
/*
|
||||
Raffle Contract
|
||||
Enter the lottery (paying some amount)
|
||||
Pick a random winner (verifiably random)
|
||||
Winner to be selected every X minutes -> completely automated
|
||||
Chainlink Oracle -> Randomness, Automated Execution (Chainlink Keeper)
|
||||
*/
|
||||
pragma solidity ^0.8.7;
|
||||
|
||||
///// UPDATE IMPORTS TO V2.5 /////
|
||||
import {VRFConsumerBaseV2Plus} from "@chainlink/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol";
|
||||
import {VRFV2PlusClient} from "@chainlink/contracts/src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol";
|
||||
|
||||
error Raffle__NotEnoughETHEntered();
|
||||
|
||||
contract Raffle is VRFConsumerBaseV2Plus {
|
||||
/* State Variables */
|
||||
uint256 private immutable i_entranceFee;
|
||||
address payable[] private s_players;
|
||||
|
||||
/* Event */
|
||||
event RaffleEnter(address indexed player);
|
||||
|
||||
constructor(
|
||||
address vrfCoordinatorV2,
|
||||
uint256 entranceFee
|
||||
) VRFConsumerBaseV2Plus(vrfCoordinatorV2) {
|
||||
i_entranceFee = entranceFee;
|
||||
}
|
||||
|
||||
function enterRaffle() public payable {
|
||||
// require(msg.value > i_entranceFee, "ETH too less!");
|
||||
if (msg.value < i_entranceFee) {
|
||||
revert Raffle__NotEnoughETHEntered();
|
||||
}
|
||||
s_players.push(payable(msg.sender));
|
||||
// Events - Update
|
||||
}
|
||||
|
||||
function requestRandomWinner() external returns (uint256 requestId) {
|
||||
// Use Chainlink VRF V2 & Chainlink keeper
|
||||
// https://docs.chain.link/vrf/v2/subscription/examples/get-a-random-number
|
||||
// 0xb91d9cab0193d3cda599df11c4889f89c4a9fef9ec403de158ea67ce1f3a9e26
|
||||
/**
|
||||
* Create subscription at https://vrf.chain.link/ (MetaMask #1)
|
||||
* Add Fund To The Created Subsciption Contract (MetaMask #2)
|
||||
* Add Consumer
|
||||
* Get Subscription ID
|
||||
* Open Remix To Prepare Deploy Consumer Contract https://docs.chain.link/vrf/v2-5/migration-from-v2
|
||||
* Change To Correct gwei limit hash address at https://docs.chain.link/vrf/v2/subscription/supported-networks
|
||||
* Adjust Setting - random words count, confirmation blocks etc.
|
||||
* Insert Subscription ID - v2 is uint64 BUT **v2.5 is uint256**
|
||||
* Deploy And Get hash address (MetaMask #3)
|
||||
* Insert in chainlink consumer (Metamask #4)
|
||||
* Ready to use, record down the consumer contract address
|
||||
* *
|
||||
* v2.5 uint256 Subscription ID - 54852953177758767717007928774683925681326589777506065303357242036079980899870
|
||||
* Admin Contract Creator address - 0xc9445e993daea4ba3f1fe1080f0f6f8c46b4d967
|
||||
* Consumer address - 0x22eec58ce2cee446051337d71d59c89cb004d1c7
|
||||
* Admin Approval Contract address - 0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B
|
||||
*/
|
||||
// Request Random Number
|
||||
//
|
||||
}
|
||||
|
||||
function fulfillRandomWords(
|
||||
uint256 requestId,
|
||||
uint256[] calldata randomWords
|
||||
) internal override {}
|
||||
|
||||
function getEntranceFee() public view returns (uint256) {
|
||||
return i_entranceFee;
|
||||
}
|
||||
|
||||
function getPlayer(uint256 index) public view returns (address) {
|
||||
return s_players[index];
|
||||
}
|
||||
}
|
44
package.json
44
package.json
@ -1,20 +1,30 @@
|
||||
{
|
||||
|
||||
"license": "Unlicense",
|
||||
"devDependencies": {
|
||||
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
|
||||
"@nomiclabs/hardhat-etherscan": "^3.1.8",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.6",
|
||||
"chai": "^5.1.1",
|
||||
"dotenv": "^16.4.5",
|
||||
"ethereum-waffle": "^4.0.10",
|
||||
"ethers": "^6.13.2",
|
||||
"hardhat": "^2.22.7",
|
||||
"hardhat-contract-sizer": "^2.10.0",
|
||||
"hardhat-deploy": "^0.12.4",
|
||||
"hardhat-gas-reporter": "^2.2.0",
|
||||
"prettier": "^3.3.3",
|
||||
"prettier-plugin-solidity": "^1.3.1",
|
||||
"solhint": "^5.0.3",
|
||||
"solidity-coverage": "^0.8.12"
|
||||
},
|
||||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
||||
"@nomicfoundation/hardhat-ethers": "^3.0.2",
|
||||
"@nomiclabs/hardhat-ethers": "npm:hardhat-deploy-ethers",
|
||||
"@nomiclabs/hardhat-etherscan": "^3.1.8",
|
||||
"@nomiclabs/hardhat-waffle": "^2.0.6",
|
||||
"chai": "^5.1.1",
|
||||
"dotenv": "^16.4.5",
|
||||
"ethereum-waffle": "^4.0.10",
|
||||
"ethers": "^6.13.2",
|
||||
"hardhat": "^2.22.7",
|
||||
"hardhat-contract-sizer": "^2.10.0",
|
||||
"hardhat-deploy": "^0.12.4",
|
||||
"hardhat-gas-reporter": "^2.2.0",
|
||||
"prettier": "^3.3.3",
|
||||
"prettier-plugin-solidity": "^1.3.1",
|
||||
"solhint": "^5.0.3",
|
||||
"solidity-coverage": "^0.8.12"
|
||||
},
|
||||
"dependencies": {
|
||||
"@chainlink/contracts": "^1.2.0",
|
||||
"@chainlink/test-helpers": "^0.0.7-alpha",
|
||||
"@chainlink/token": "^1.1.0",
|
||||
"@openzeppelin/contracts": "^5.0.2",
|
||||
"babel-eslint": "^10.1.0"
|
||||
},
|
||||
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user