Last active
June 21, 2021 13:32
-
-
Save PatrickAlphaC/4d915a385211193967ec28cb883f4445 to your computer and use it in GitHub Desktop.
Rinkeby Random Number Consumer: Deploy with https://remix.ethereum.org/#version=soljson-v0.6.12+commit.27d51765.js&optimize=false&runs=200&gist=4d915a385211193967ec28cb883f4445
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
pragma solidity 0.6.6; | |
import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol"; | |
/** | |
* THIS IS AN EXAMPLE CONTRACT WHICH USES HARDCODED VALUES FOR CLARITY. | |
* PLEASE DO NOT USE THIS CODE IN PRODUCTION. | |
*/ | |
contract RandomNumberConsumer is VRFConsumerBase { | |
bytes32 internal keyHash; | |
uint256 internal fee; | |
uint256 public randomResult; | |
bytes32 public reqId; | |
/** | |
* Constructor inherits VRFConsumerBase | |
* | |
* Network: Rinkeby | |
* Chainlink VRF Coordinator address: 0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B | |
* LINK token address: 0x01be23585060835e02b77ef475b0cc51aa1e0709 | |
* Key Hash: 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311 | |
*/ | |
constructor() | |
VRFConsumerBase( | |
0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B, // VRF Coordinator | |
0x01BE23585060835E02B77ef475b0Cc51aA1e0709 // LINK Token | |
) public | |
{ | |
keyHash = 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311; | |
fee = 0.1 * 10 ** 18; // 0.1 LINK (Varies by network) | |
} | |
/** | |
* Requests randomness from a user-provided seed | |
*/ | |
function getRandomNumber(uint256 userProvidedSeed) public returns (bytes32 requestId) { | |
require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet"); | |
return requestRandomness(keyHash, fee, userProvidedSeed); | |
} | |
/** | |
* Callback function used by VRF Coordinator | |
*/ | |
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override { | |
randomResult = randomness; | |
reqId = requestId; | |
} | |
// function withdrawLink() external {} - Implement a withdraw function to avoid locking your LINK in the contract | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment