Last active
June 14, 2021 13:00
-
-
Save PatrickAlphaC/970cde23d9fec804597c5ad5a0b9e360 to your computer and use it in GitHub Desktop.
Kovan Chainlink VRF. Deploy using: https://remix.ethereum.org/#version=soljson-v0.6.7+commit.b8d736ae.js&optimize=false&evmVersion=null&gist=970cde23d9fec804597c5ad5a0b9e360
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
/** This example code is designed to quickly deploy an example contract using Remix. | |
* If you have never used Remix, try our example walkthrough: https://docs.chain.link/docs/example-walkthrough | |
* You will need testnet ETH and LINK. | |
* - Kovan ETH faucet: https://faucet.kovan.network/ | |
* - Kovan LINK faucet: https://kovan.chain.link/ | |
*/ | |
// VRF Coordinator 0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9 | |
// Key Hash 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641 | |
pragma solidity 0.6.6; | |
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/master/evm-contracts/src/v0.6/VRFConsumerBase.sol"; | |
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 | |
) public | |
{ | |
keyHash = 0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4; | |
fee = 0.1 * 10 ** 18; // 0.1 LINK | |
} | |
/** | |
* 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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment