Last active
October 10, 2021 05:22
-
-
Save bliotti/fe8ada590665df91f95e598a8b576a87 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
This file contains hidden or 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
// SPDX-License-Identifier: MIT | |
pragma solidity ^0.8.7; | |
import "@chainlink/contracts/src/v0.8/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; | |
/** | |
* Constructor inherits VRFConsumerBase | |
* | |
* Network: Kovan | |
* Chainlink VRF Coordinator address: 0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9 | |
* LINK token address: 0xa36085F69e2889c224210F603D836748e7dC0088 | |
* Key Hash: 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4 | |
*/ | |
constructor() | |
VRFConsumerBase( | |
0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9, // VRF Coordinator | |
0xa36085F69e2889c224210F603D836748e7dC0088 // LINK Token | |
) | |
{ | |
keyHash = 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4; | |
fee = 0.1 * 10 ** 18; // 0.1 LINK (Varies by network) | |
} | |
/** | |
* Requests randomness | |
*/ | |
function getRandomNumber() public returns (bytes32 requestId) { | |
require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet"); | |
return requestRandomness(keyHash, fee); | |
} | |
/** | |
* Callback function used by VRF Coordinator | |
*/ | |
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override { | |
randomResult = randomness; | |
} | |
function expand(uint256 randomValue, uint256 n) public pure returns (uint256[] memory expandedValues) { | |
expandedValues = new uint256[](n); | |
for (uint256 i = 0; i < n; i++) { | |
expandedValues[i] = uint256(keccak256(abi.encode(randomValue, i))); | |
} | |
return expandedValues; //100208114230674489997013616521242470982922106172305283620744374300051332384147,85793124556412524655870032413234722449119807016500432562874227669369210083195,76189536863289785482325822530373094047900864550104100775686888010789098010164,110124770397138912600286235162399105874189706750868561539894888291307652913478,18346633206507869486917886290075650863197642099690172666713532462052685979308 | |
} | |
// 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