Created
December 24, 2021 15:04
-
-
Save nikaluka/15769b69294f062a9f25eaa850caa8df 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 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"; | |
import "http://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/VRFConsumerBase.sol"; | |
contract RandomNumberConsumer is VRFConsumerBase { | |
bytes32 internal keyHash; | |
uint256 internal fee; | |
uint256 public randomResult; | |
// mapping(bytes32 => uint256) public apiRequestId; | |
mapping(bytes32 => uint256) public requestIdToRandomNumber; | |
mapping(address => uint) public requestIdToAddress; | |
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) { | |
require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet"); | |
bytes32 random = requestRandomness(keyHash, fee); | |
return random; | |
} | |
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override { | |
randomResult = randomness % 26 + 5; | |
requestIdToRandomNumber[requestId] = randomness; | |
requestIdToAddress[msg.sender]=randomResult; | |
} | |
function getMap1(address _adr) public view returns(uint){ | |
return requestIdToAddress[_adr]; | |
} | |
function withdrawLink() external { | |
require(LINK.transfer(msg.sender, LINK.balanceOf(address(this))), "Unable to transfer"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment