Last active
November 13, 2021 16:08
-
-
Save JimLynchCodes/79389186891079cc9b7cae14beff6aa0 to your computer and use it in GitHub Desktop.
An example that demonstrates how to get random numbers from chainlink
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: GPL-3.0 | |
pragma solidity 0.8.8; | |
pragma experimental ABIEncoderV2; | |
import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol"; | |
contract Example is VRFConsumerBase { | |
// on Rinkeby Network | |
address __vrfCoordinatorAddress = 0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B; | |
address __linkTokenAddress = 0x01BE23585060835E02B77ef475b0Cc51aA1e0709; | |
bytes32 __oracleKeyhash = 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311; | |
uint256 fee; | |
bytes32 keyHash; | |
event Something(uint256 ok); | |
constructor() VRFConsumerBase(__vrfCoordinatorAddress, __linkTokenAddress) public { | |
keyHash = __oracleKeyhash; | |
fee = 0.1 * 10 ** 18; // 0.1 Link | |
} | |
function getRandomNumber(uint256 userProvidedSeed) public returns (bytes32 requestId) { | |
return requestRandomness(keyHash, fee); | |
} | |
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override { | |
emit Something(randomness); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment