More Info
Private Name Tags
ContractCreator
Sponsored
Latest 5 from a total of 5 transactions
Loading...
Loading
Contract Name:
RNGChainlink
Compiler Version
v0.6.6+commit.6c089d02
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.6.6; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/utils/SafeCast.sol"; // import "@openzeppelin/contracts/math/SafeMath.sol"; import "@chainlink/contracts/src/v0.6/VRFConsumerBase.sol"; import "./RNGInterface.sol"; contract RNGChainlink is RNGInterface, VRFConsumerBase, Ownable { // using SafeMath for uint256; using SafeCast for uint256; event KeyHashSet(bytes32 keyHash); event FeeSet(uint256 fee); event VrfCoordinatorSet(address indexed vrfCoordinator); event VRFRequested(uint256 indexed requestId, bytes32 indexed chainlinkRequestId); /// @dev The keyhash used by the Chainlink VRF bytes32 public keyHash; /// @dev The request fee of the Chainlink VRF uint256 public fee; /// @dev A counter for the number of requests made used for request ids uint32 public requestCount; /// @dev A list of random numbers from past requests mapped by request id mapping(uint32 => uint256) internal randomNumbers; /// @dev A list of blocks to be locked at based on past requests mapped by request id mapping(uint32 => uint32) internal requestLockBlock; /// @dev A mapping from Chainlink request ids to internal request ids mapping(bytes32 => uint32) internal chainlinkRequestIds; /// @dev Public constructor constructor(address _vrfCoordinator, address _link) public VRFConsumerBase(_vrfCoordinator, _link) { emit VrfCoordinatorSet(_vrfCoordinator); } function getLink() external view returns (address) { return address(LINK); } /// @notice Allows governance to set the VRF keyhash /// @param _keyhash The keyhash to be used by the VRF function setKeyhash(bytes32 _keyhash) external onlyOwner { keyHash = _keyhash; emit KeyHashSet(keyHash); } /// @notice Allows governance to set the fee per request required by the VRF /// @param _fee The fee to be charged for a request function setFee(uint256 _fee) external onlyOwner { fee = _fee; emit FeeSet(fee); } /// @notice Gets the last request id used by the RNG service /// @return requestId The last request id used in the last request function getLastRequestId() external override view returns (uint32 requestId) { return requestCount; } /// @notice Gets the Fee for making a Request against an RNG service /// @return feeToken The address of the token that is used to pay fees /// @return requestFee The fee required to be paid to make a request function getRequestFee() external override view returns (address feeToken, uint256 requestFee) { return (address(LINK), fee); } /// @notice Sends a request for a random number to the 3rd-party service /// @dev Some services will complete the request immediately, others may have a time-delay /// @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF /// @return requestId The ID of the request used to get the results of the RNG service /// @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. The calling contract /// should "lock" all activity until the result is available via the `requestId` function requestRandomNumber() external override returns (uint32 requestId, uint32 lockBlock) { uint256 seed = _getSeed(); lockBlock = uint32(block.number); // collect fee for payment require(LINK.transferFrom(msg.sender, address(this), fee), "RNGChainlink/fee-transfer-failed"); // send request (costs fee) requestId = _requestRandomness(seed); requestLockBlock[requestId] = lockBlock; emit RandomNumberRequested(requestId, msg.sender); } /// @notice Checks if the request for randomness from the 3rd-party service has completed /// @dev For time-delayed requests, this function is used to check/confirm completion /// @param requestId The ID of the request used to get the results of the RNG service /// @return isCompleted True if the request has completed and a random number is available, false otherwise function isRequestComplete(uint32 requestId) external override view returns (bool isCompleted) { return randomNumbers[requestId] != 0; } /// @notice Gets the random number produced by the 3rd-party service /// @param requestId The ID of the request used to get the results of the RNG service /// @return randomNum The random number function randomNumber(uint32 requestId) external override returns (uint256 randomNum) { return randomNumbers[requestId]; } /// @dev Requests a new random number from the Chainlink VRF /// @dev The result of the request is returned in the function `fulfillRandomness` /// @param seed The seed used as entropy for the request function _requestRandomness(uint256 seed) internal returns (uint32 requestId) { // Get next request ID requestId = _getNextRequestId(); // Complete request bytes32 vrfRequestId = requestRandomness(keyHash, fee, seed); chainlinkRequestIds[vrfRequestId] = requestId; emit VRFRequested(requestId, vrfRequestId); } /// @notice Callback function used by VRF Coordinator /// @dev The VRF Coordinator will only send this function verified responses. /// @dev The VRF Coordinator will not pass randomness that could not be verified. function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override { uint32 internalRequestId = chainlinkRequestIds[requestId]; // Store random value randomNumbers[internalRequestId] = randomness; emit RandomNumberCompleted(internalRequestId, randomness); } /// @dev Gets the next consecutive request ID to be used /// @return requestId The ID to be used for the next request function _getNextRequestId() internal returns (uint32 requestId) { requestCount = uint256(requestCount).add(1).toUint32(); requestId = requestCount; } /// @dev Gets a seed for a random number from the latest available blockhash /// @return seed The seed to be used for generating a random number function _getSeed() internal virtual view returns (uint256 seed) { return uint256(blockhash(block.number - 1)); } }
pragma solidity ^0.6.0; import { SafeMath as SafeMath_Chainlink } from "./vendor/SafeMath.sol"; import "./interfaces/LinkTokenInterface.sol"; import "./VRFRequestIDBase.sol"; /** **************************************************************************** * @notice Interface for contracts using VRF randomness * ***************************************************************************** * @dev PURPOSE * * @dev Reggie the Random Oracle (not his real job) wants to provide randomness * @dev to Vera the verifier in such a way that Vera can be sure he's not * @dev making his output up to suit himself. Reggie provides Vera a public key * @dev to which he knows the secret key. Each time Vera provides a seed to * @dev Reggie, he gives back a value which is computed completely * @dev deterministically from the seed and the secret key. * * @dev Reggie provides a proof by which Vera can verify that the output was * @dev correctly computed once Reggie tells it to her, but without that proof, * @dev the output is indistinguishable to her from a uniform random sample * @dev from the output space. * * @dev The purpose of this contract is to make it easy for unrelated contracts * @dev to talk to Vera the verifier about the work Reggie is doing, to provide * @dev simple access to a verifiable source of randomness. * ***************************************************************************** * @dev USAGE * * @dev Calling contracts must inherit from VRFConsumerInterface, and can * @dev initialize VRFConsumerInterface's attributes in their constructor as * @dev shown: * * @dev contract VRFConsumer { * @dev constuctor(<other arguments>, address _vrfCoordinator, address _link) * @dev VRFConsumerBase(_vrfCoordinator, _link) public { * @dev <initialization with other arguments goes here> * @dev } * @dev } * * @dev The oracle will have given you an ID for the VRF keypair they have * @dev committed to (let's call it keyHash), and have told you the minimum LINK * @dev price for VRF service. Make sure your contract has sufficient LINK, and * @dev call requestRandomness(keyHash, fee, seed), where seed is the input you * @dev want to generate randomness from. * * @dev Once the VRFCoordinator has received and validated the oracle's response * @dev to your request, it will call your contract's fulfillRandomness method. * * @dev The randomness argument to fulfillRandomness is the actual random value * @dev generated from your seed. * * @dev The requestId argument is generated from the keyHash and the seed by * @dev makeRequestId(keyHash, seed). If your contract could have concurrent * @dev requests open, you can use the requestId to track which seed is * @dev associated with which randomness. See VRFRequestIDBase.sol for more * @dev details. * * @dev Colliding `requestId`s are cryptographically impossible as long as seeds * @dev differ. (Which is critical to making unpredictable randomness! See the * @dev next section.) * * ***************************************************************************** * @dev SECURITY CONSIDERATIONS * * @dev Since the ultimate input to the VRF is mixed with the block hash of the * @dev block in which the request is made, user-provided seeds have no impact * @dev on its economic security properties. They are only included for API * @dev compatability with previous versions of this contract. * * @dev Since the block hash of the block which contains the requestRandomness() * @dev call is mixed into the input to the VRF *last*, a sufficiently powerful * @dev miner could, in principle, fork the blockchain to evict the block * @dev containing the request, forcing the request to be included in a * @dev different block with a different hash, and therefore a different input * @dev to the VRF. However, such an attack would incur a substantial economic * @dev cost. This cost scales with the number of blocks the VRF oracle waits * @dev until it calls fulfillRandomness(). */ abstract contract VRFConsumerBase is VRFRequestIDBase { using SafeMath_Chainlink for uint256; /** * @notice fulfillRandomness handles the VRF response. Your contract must * @notice implement it. * * @dev The VRFCoordinator expects a calling contract to have a method with * @dev this signature, and will trigger it once it has verified the proof * @dev associated with the randomness (It is triggered via a call to * @dev rawFulfillRandomness, below.) * * @param requestId The Id initially returned by requestRandomness * @param randomness the VRF output */ function fulfillRandomness(bytes32 requestId, uint256 randomness) internal virtual; /** * @notice requestRandomness initiates a request for VRF output given _seed * * @dev See "SECURITY CONSIDERATIONS" above for more information on _seed. * * @dev The fulfillRandomness method receives the output, once it's provided * @dev by the Oracle, and verified by the vrfCoordinator. * * @dev The _keyHash must already be registered with the VRFCoordinator, and * @dev the _fee must exceed the fee specified during registration of the * @dev _keyHash. * * @param _keyHash ID of public key against which randomness is generated * @param _fee The amount of LINK to send with the request * @param _seed seed mixed into the input of the VRF * * @return requestId unique ID for this request * * @dev The returned requestId can be used to distinguish responses to * * @dev concurrent requests. It is passed as the first argument to * @dev fulfillRandomness. */ function requestRandomness(bytes32 _keyHash, uint256 _fee, uint256 _seed) public returns (bytes32 requestId) { LINK.transferAndCall(vrfCoordinator, _fee, abi.encode(_keyHash, _seed)); // This is the seed passed to VRFCoordinator. The oracle will mix this with // the hash of the block containing this request to obtain the seed/input // which is finally passed to the VRF cryptographic machinery. uint256 vRFSeed = makeVRFInputSeed(_keyHash, _seed, address(this), nonces[_keyHash]); // nonces[_keyHash] must stay in sync with // VRFCoordinator.nonces[_keyHash][this], which was incremented by the above // successful LINK.transferAndCall (in VRFCoordinator.randomnessRequest). // This provides protection against the user repeating their input // seed, which would result in a predictable/duplicate output. nonces[_keyHash] = nonces[_keyHash].add(1); return makeRequestId(_keyHash, vRFSeed); } LinkTokenInterface immutable internal LINK; address immutable private vrfCoordinator; // Nonces for each VRF key from which randomness has been requested. // // Must stay in sync with VRFCoordinator[_keyHash][this] mapping(bytes32 /* keyHash */ => uint256 /* nonce */) public nonces; constructor(address _vrfCoordinator, address _link) public { vrfCoordinator = _vrfCoordinator; LINK = LinkTokenInterface(_link); } // rawFulfillRandomness is called by VRFCoordinator when it receives a valid VRF // proof. rawFulfillRandomness then calls fulfillRandomness, after validating // the origin of the call function rawFulfillRandomness(bytes32 requestId, uint256 randomness) external { require(msg.sender == vrfCoordinator, "Only VRFCoordinator can fulfill"); fulfillRandomness(requestId, randomness); } }
pragma solidity ^0.6.0; contract VRFRequestIDBase { /** * @notice returns the seed which is actually input to the VRF coordinator * * @dev To prevent repetition of VRF output due to repetition of the * @dev user-supplied seed, that seed is combined in a hash with the * @dev user-specific nonce, and the address of the consuming contract. The * @dev risk of repetition is mostly mitigated by inclusion of a blockhash in * @dev the final seed, but the nonce does protect against repetition in * @dev requests which are included in a single block. * * @param _userSeed VRF seed input provided by user * @param _requester Address of the requesting contract * @param _nonce User-specific nonce at the time of the request */ function makeVRFInputSeed(bytes32 _keyHash, uint256 _userSeed, address _requester, uint256 _nonce) internal pure returns (uint256) { return uint256(keccak256(abi.encode(_keyHash, _userSeed, _requester, _nonce))); } /** * @notice Returns the id for this request * @param _keyHash The serviceAgreement ID to be used for this request * @param _vRFInputSeed The seed to be passed directly to the VRF * @return The id for this request * * @dev Note that _vRFInputSeed is not the seed passed by the consuming * @dev contract, but the one generated by makeVRFInputSeed */ function makeRequestId( bytes32 _keyHash, uint256 _vRFInputSeed) internal pure returns (bytes32) { return keccak256(abi.encodePacked(_keyHash, _vRFInputSeed)); } }
pragma solidity ^0.6.0; interface LinkTokenInterface { function allowance(address owner, address spender) external view returns (uint256 remaining); function approve(address spender, uint256 value) external returns (bool success); function balanceOf(address owner) external view returns (uint256 balance); function decimals() external view returns (uint8 decimalPlaces); function decreaseApproval(address spender, uint256 addedValue) external returns (bool success); function increaseApproval(address spender, uint256 subtractedValue) external; function name() external view returns (string memory tokenName); function symbol() external view returns (string memory tokenSymbol); function totalSupply() external view returns (uint256 totalTokensIssued); function transfer(address to, uint256 value) external returns (bool success); function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool success); function transferFrom(address from, address to, uint256 value) external returns (bool success); }
pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's arithmetic operations with added overflow * checks. * * Arithmetic operations in Solidity wrap on overflow. This can easily result * in bugs, because programmers usually assume that an overflow raises an * error, which is the standard behavior in high level programming languages. * `SafeMath` restores this intuition by reverting the transaction when an * operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { uint256 c = a + b; require(c >= a, "SafeMath: addition overflow"); return c; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { require(b <= a, "SafeMath: subtraction overflow"); uint256 c = a - b; return c; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { // Gas optimization: this is cheaper than requiring 'a' not being zero, but the // benefit is lost if 'b' is also tested. // See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522 if (a == 0) { return 0; } uint256 c = a * b; require(c / a == b, "SafeMath: multiplication overflow"); return c; } /** * @dev Returns the integer division of two unsigned integers. Reverts on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { // Solidity only automatically asserts when dividing by 0 require(b > 0, "SafeMath: division by zero"); uint256 c = a / b; // assert(a == b * c + a % b); // There is no case in which this doesn't hold return c; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * Reverts when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { require(b != 0, "SafeMath: modulo by zero"); return a % b; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /* * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with GSN meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address payable) { return msg.sender; } function _msgData() internal view virtual returns (bytes memory) { this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691 return msg.data; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.6.0; import "../GSN/Context.sol"; /** * @dev Contract module which provides a basic access control mechanism, where * there is an account (an owner) that can be granted exclusive access to * specific functions. * * By default, the owner account will be the one that deploys the contract. This * can later be changed with {transferOwnership}. * * This module is used through inheritance. It will make available the modifier * `onlyOwner`, which can be applied to your functions to restrict their use to * the owner. */ contract Ownable is Context { address private _owner; event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); /** * @dev Initializes the contract setting the deployer as the initial owner. */ constructor () internal { address msgSender = _msgSender(); _owner = msgSender; emit OwnershipTransferred(address(0), msgSender); } /** * @dev Returns the address of the current owner. */ function owner() public view returns (address) { return _owner; } /** * @dev Throws if called by any account other than the owner. */ modifier onlyOwner() { require(_owner == _msgSender(), "Ownable: caller is not the owner"); _; } /** * @dev Leaves the contract without owner. It will not be possible to call * `onlyOwner` functions anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing any functionality that is only available to the owner. */ function renounceOwnership() public virtual onlyOwner { emit OwnershipTransferred(_owner, address(0)); _owner = address(0); } /** * @dev Transfers ownership of the contract to a new account (`newOwner`). * Can only be called by the current owner. */ function transferOwnership(address newOwner) public virtual onlyOwner { require(newOwner != address(0), "Ownable: new owner is the zero address"); emit OwnershipTransferred(_owner, newOwner); _owner = newOwner; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.6.0; /** * @dev Wrappers over Solidity's uintXX/intXX casting operators with added overflow * checks. * * Downcasting from uint256/int256 in Solidity does not revert on overflow. This can * easily result in undesired exploitation or bugs, since developers usually * assume that overflows raise errors. `SafeCast` restores this intuition by * reverting the transaction when such an operation overflows. * * Using this library instead of the unchecked operations eliminates an entire * class of bugs, so it's recommended to use it always. * * Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing * all math on `uint256` and `int256` and then downcasting. */ library SafeCast { /** * @dev Returns the downcasted uint128 from uint256, reverting on * overflow (when the input is greater than largest uint128). * * Counterpart to Solidity's `uint128` operator. * * Requirements: * * - input must fit into 128 bits */ function toUint128(uint256 value) internal pure returns (uint128) { require(value < 2**128, "SafeCast: value doesn\'t fit in 128 bits"); return uint128(value); } /** * @dev Returns the downcasted uint64 from uint256, reverting on * overflow (when the input is greater than largest uint64). * * Counterpart to Solidity's `uint64` operator. * * Requirements: * * - input must fit into 64 bits */ function toUint64(uint256 value) internal pure returns (uint64) { require(value < 2**64, "SafeCast: value doesn\'t fit in 64 bits"); return uint64(value); } /** * @dev Returns the downcasted uint32 from uint256, reverting on * overflow (when the input is greater than largest uint32). * * Counterpart to Solidity's `uint32` operator. * * Requirements: * * - input must fit into 32 bits */ function toUint32(uint256 value) internal pure returns (uint32) { require(value < 2**32, "SafeCast: value doesn\'t fit in 32 bits"); return uint32(value); } /** * @dev Returns the downcasted uint16 from uint256, reverting on * overflow (when the input is greater than largest uint16). * * Counterpart to Solidity's `uint16` operator. * * Requirements: * * - input must fit into 16 bits */ function toUint16(uint256 value) internal pure returns (uint16) { require(value < 2**16, "SafeCast: value doesn\'t fit in 16 bits"); return uint16(value); } /** * @dev Returns the downcasted uint8 from uint256, reverting on * overflow (when the input is greater than largest uint8). * * Counterpart to Solidity's `uint8` operator. * * Requirements: * * - input must fit into 8 bits. */ function toUint8(uint256 value) internal pure returns (uint8) { require(value < 2**8, "SafeCast: value doesn\'t fit in 8 bits"); return uint8(value); } /** * @dev Converts a signed int256 into an unsigned uint256. * * Requirements: * * - input must be greater than or equal to 0. */ function toUint256(int256 value) internal pure returns (uint256) { require(value >= 0, "SafeCast: value must be positive"); return uint256(value); } /** * @dev Returns the downcasted int128 from int256, reverting on * overflow (when the input is less than smallest int128 or * greater than largest int128). * * Counterpart to Solidity's `int128` operator. * * Requirements: * * - input must fit into 128 bits * * _Available since v3.1._ */ function toInt128(int256 value) internal pure returns (int128) { require(value >= -2**127 && value < 2**127, "SafeCast: value doesn\'t fit in 128 bits"); return int128(value); } /** * @dev Returns the downcasted int64 from int256, reverting on * overflow (when the input is less than smallest int64 or * greater than largest int64). * * Counterpart to Solidity's `int64` operator. * * Requirements: * * - input must fit into 64 bits * * _Available since v3.1._ */ function toInt64(int256 value) internal pure returns (int64) { require(value >= -2**63 && value < 2**63, "SafeCast: value doesn\'t fit in 64 bits"); return int64(value); } /** * @dev Returns the downcasted int32 from int256, reverting on * overflow (when the input is less than smallest int32 or * greater than largest int32). * * Counterpart to Solidity's `int32` operator. * * Requirements: * * - input must fit into 32 bits * * _Available since v3.1._ */ function toInt32(int256 value) internal pure returns (int32) { require(value >= -2**31 && value < 2**31, "SafeCast: value doesn\'t fit in 32 bits"); return int32(value); } /** * @dev Returns the downcasted int16 from int256, reverting on * overflow (when the input is less than smallest int16 or * greater than largest int16). * * Counterpart to Solidity's `int16` operator. * * Requirements: * * - input must fit into 16 bits * * _Available since v3.1._ */ function toInt16(int256 value) internal pure returns (int16) { require(value >= -2**15 && value < 2**15, "SafeCast: value doesn\'t fit in 16 bits"); return int16(value); } /** * @dev Returns the downcasted int8 from int256, reverting on * overflow (when the input is less than smallest int8 or * greater than largest int8). * * Counterpart to Solidity's `int8` operator. * * Requirements: * * - input must fit into 8 bits. * * _Available since v3.1._ */ function toInt8(int256 value) internal pure returns (int8) { require(value >= -2**7 && value < 2**7, "SafeCast: value doesn\'t fit in 8 bits"); return int8(value); } /** * @dev Converts an unsigned uint256 into a signed int256. * * Requirements: * * - input must be less than or equal to maxInt256. */ function toInt256(uint256 value) internal pure returns (int256) { require(value < 2**255, "SafeCast: value doesn't fit in an int256"); return int256(value); } }
// SPDX-License-Identifier: GPL-3.0 pragma solidity >=0.6.0; /// @title Random Number Generator Interface /// @notice Provides an interface for requesting random numbers from 3rd-party RNG services (Chainlink VRF, Starkware VDF, etc..) interface RNGInterface { /// @notice Emitted when a new request for a random number has been submitted /// @param requestId The indexed ID of the request used to get the results of the RNG service /// @param sender The indexed address of the sender of the request event RandomNumberRequested(uint32 indexed requestId, address indexed sender); /// @notice Emitted when an existing request for a random number has been completed /// @param requestId The indexed ID of the request used to get the results of the RNG service /// @param randomNumber The random number produced by the 3rd-party service event RandomNumberCompleted(uint32 indexed requestId, uint256 randomNumber); /// @notice Gets the last request id used by the RNG service /// @return requestId The last request id used in the last request function getLastRequestId() external view returns (uint32 requestId); /// @notice Gets the Fee for making a Request against an RNG service /// @return feeToken The address of the token that is used to pay fees /// @return requestFee The fee required to be paid to make a request function getRequestFee() external view returns (address feeToken, uint256 requestFee); /// @notice Sends a request for a random number to the 3rd-party service /// @dev Some services will complete the request immediately, others may have a time-delay /// @dev Some services require payment in the form of a token, such as $LINK for Chainlink VRF /// @return requestId The ID of the request used to get the results of the RNG service /// @return lockBlock The block number at which the RNG service will start generating time-delayed randomness. The calling contract /// should "lock" all activity until the result is available via the `requestId` function requestRandomNumber() external returns (uint32 requestId, uint32 lockBlock); /// @notice Checks if the request for randomness from the 3rd-party service has completed /// @dev For time-delayed requests, this function is used to check/confirm completion /// @param requestId The ID of the request used to get the results of the RNG service /// @return isCompleted True if the request has completed and a random number is available, false otherwise function isRequestComplete(uint32 requestId) external view returns (bool isCompleted); /// @notice Gets the random number produced by the 3rd-party service /// @param requestId The ID of the request used to get the results of the RNG service /// @return randomNum The random number function randomNumber(uint32 requestId) external returns (uint256 randomNum); }
{ "evmVersion": "istanbul", "libraries": {}, "metadata": { "bytecodeHash": "ipfs", "useLiteralContent": true }, "optimizer": { "enabled": true, "runs": 200 }, "remappings": [], "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "abi" ] } } }
Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
[{"inputs":[{"internalType":"address","name":"_vrfCoordinator","type":"address"},{"internalType":"address","name":"_link","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"FeeSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes32","name":"keyHash","type":"bytes32"}],"name":"KeyHashSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"requestId","type":"uint32"},{"indexed":false,"internalType":"uint256","name":"randomNumber","type":"uint256"}],"name":"RandomNumberCompleted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"requestId","type":"uint32"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RandomNumberRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"requestId","type":"uint256"},{"indexed":true,"internalType":"bytes32","name":"chainlinkRequestId","type":"bytes32"}],"name":"VRFRequested","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"vrfCoordinator","type":"address"}],"name":"VrfCoordinatorSet","type":"event"},{"inputs":[],"name":"fee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLastRequestId","outputs":[{"internalType":"uint32","name":"requestId","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getLink","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getRequestFee","outputs":[{"internalType":"address","name":"feeToken","type":"address"},{"internalType":"uint256","name":"requestFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"requestId","type":"uint32"}],"name":"isRequestComplete","outputs":[{"internalType":"bool","name":"isCompleted","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"keyHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"nonces","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"requestId","type":"uint32"}],"name":"randomNumber","outputs":[{"internalType":"uint256","name":"randomNum","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"},{"internalType":"uint256","name":"randomness","type":"uint256"}],"name":"rawFulfillRandomness","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"requestCount","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"requestRandomNumber","outputs":[{"internalType":"uint32","name":"requestId","type":"uint32"},{"internalType":"uint32","name":"lockBlock","type":"uint32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_keyHash","type":"bytes32"},{"internalType":"uint256","name":"_fee","type":"uint256"},{"internalType":"uint256","name":"_seed","type":"uint256"}],"name":"requestRandomness","outputs":[{"internalType":"bytes32","name":"requestId","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_fee","type":"uint256"}],"name":"setFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_keyhash","type":"bytes32"}],"name":"setKeyhash","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"}]
Contract Creation Code
60c060405234801561001057600080fd5b50604051610e59380380610e598339818101604052604081101561003357600080fd5b5080516020909101516001600160601b0319606083811b821660a05282901b1660805260006100696001600160e01b036100f216565b600180546001600160a01b0319166001600160a01b038316908117909155604051919250906000907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908290a3506040516001600160a01b038316907f4cc41e06d3d0588be9be0e1469ba1934c4bd1cb8f4f70adf2aa31f4b92134b2790600090a250506100f6565b3390565b60805160601c60a05160601c610d26610133600039806106b8528061079552508061030f52806105745280610766528061092c5250610d266000f3fe608060405234801561001057600080fd5b506004361061010b5760003560e01c80638678a7b2116100a25780639e317f12116100715780639e317f121461028e578063dc6cfe10146102ab578063ddca3f43146102d4578063e2d84e23146102dc578063f2fde38b146102e45761010b565b80638678a7b2146101f95780638da5cb5b1461022457806394985ddd146102485780639d2a5f981461026b5761010b565b806361728f39116100de57806361728f391461019b5780636309b773146101b557806369fe0e2d146101d4578063715018a6146101f15761010b565b80630d37b5371461011057806319c2b4c31461013b5780633a19b9bc1461015c5780635badbe4c14610193575b600080fd5b61011861030a565b604080516001600160a01b03909316835260208301919091528051918290030190f35b610143610331565b6040805163ffffffff9092168252519081900360200190f35b61017f6004803603602081101561017257600080fd5b503563ffffffff1661033d565b604080519115158252519081900360200190f35b610143610357565b6101a3610363565b60408051918252519081900360200190f35b6101d2600480360360208110156101cb57600080fd5b5035610369565b005b6101d2600480360360208110156101ea57600080fd5b50356103fc565b6101d261048f565b610201610531565b6040805163ffffffff938416815291909216602082015281519081900390910190f35b61022c61069e565b604080516001600160a01b039092168252519081900360200190f35b6101d26004803603604081101561025e57600080fd5b50803590602001356106ad565b6101a36004803603602081101561028157600080fd5b503563ffffffff16610738565b6101a3600480360360208110156102a457600080fd5b5035610750565b6101a3600480360360608110156102c157600080fd5b5080359060208101359060400135610762565b6101a3610924565b61022c61092a565b6101d2600480360360208110156102fa57600080fd5b50356001600160a01b031661094e565b6003547f000000000000000000000000000000000000000000000000000000000000000091565b60045463ffffffff1690565b63ffffffff16600090815260056020526040902054151590565b60045463ffffffff1681565b60025481565b610371610a47565b6001546001600160a01b039081169116146103c1576040805162461bcd60e51b81526020600482018190526024820152600080516020610cab833981519152604482015290519081900360640190fd5b60028190556040805182815290517fd013f86c8346660ebf421351882cd1b3c2f91883092df1800264c656b0db0cc69181900360200190a150565b610404610a47565b6001546001600160a01b03908116911614610454576040805162461bcd60e51b81526020600482018190526024820152600080516020610cab833981519152604482015290519081900360640190fd5b60038190556040805182815290517f20461e09b8e557b77e107939f9ce6544698123aad0fc964ac5cc59b7df2e608f9181900360200190a150565b610497610a47565b6001546001600160a01b039081169116146104e7576040805162461bcd60e51b81526020600482018190526024820152600080516020610cab833981519152604482015290519081900360640190fd5b6001546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600180546001600160a01b0319169055565b600080600061053e610a4b565b600354604080516323b872dd60e01b81523360048201523060248201526044810192909252514394509192506001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016916323b872dd916064808201926020929091908290030181600087803b1580156105bd57600080fd5b505af11580156105d1573d6000803e3d6000fd5b505050506040513d60208110156105e757600080fd5b505161063a576040805162461bcd60e51b815260206004820181905260248201527f524e47436861696e6c696e6b2f6665652d7472616e736665722d6661696c6564604482015290519081900360640190fd5b61064381610a54565b63ffffffff818116600081815260066020526040808220805463ffffffff1916948816949094179093559151929550339290917fcf635b20f2defc1e71326dc4f0b616fa676e29a5bae87da19fcaddc550b33f0391a3509091565b6001546001600160a01b031690565b336001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000161461072a576040805162461bcd60e51b815260206004820152601f60248201527f4f6e6c7920565246436f6f7264696e61746f722063616e2066756c66696c6c00604482015290519081900360640190fd5b6107348282610ac8565b5050565b63ffffffff1660009081526005602052604090205490565b60006020819052908152604090205481565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316634000aea07f000000000000000000000000000000000000000000000000000000000000000085878660405160200180838152602001828152602001925050506040516020818303038152906040526040518463ffffffff1660e01b815260040180846001600160a01b03166001600160a01b0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561084757818101518382015260200161082f565b50505050905090810190601f1680156108745780820380516001836020036101000a031916815260200191505b50945050505050602060405180830381600087803b15801561089557600080fd5b505af11580156108a9573d6000803e3d6000fd5b505050506040513d60208110156108bf57600080fd5b50506000848152602081905260408120546108df90869085903090610b24565b60008681526020819052604090205490915061090290600163ffffffff610b6b16565b60008681526020819052604090205561091b8582610bcc565b95945050505050565b60035481565b7f000000000000000000000000000000000000000000000000000000000000000090565b610956610a47565b6001546001600160a01b039081169116146109a6576040805162461bcd60e51b81526020600482018190526024820152600080516020610cab833981519152604482015290519081900360640190fd5b6001600160a01b0381166109eb5760405162461bcd60e51b8152600401808060200182810382526026815260200180610c856026913960400191505060405180910390fd5b6001546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b3390565b60001943014090565b6000610a5e610bf8565b90506000610a7160025460035485610762565b600081815260076020526040808220805463ffffffff191663ffffffff87169081179091559051929350839290917ff7617d06180c24c92bad8c8436c3ae97409a09e1f5655da6c0807f50c5f9674891a350919050565b60008281526007602090815260408083205463ffffffff1680845260058352928190208490558051848152905183927f629394f18de7accce1179c28c39be59503a57cbcf45980a2772743b041b36271928290030190a2505050565b60408051602080820196909652808201949094526001600160a01b039290921660608401526080808401919091528151808403909101815260a09092019052805191012090565b600082820183811015610bc5576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b604080516020808201949094528082019290925280518083038201815260609092019052805191012090565b600454600090610c1d90610c189063ffffffff90811690600190610b6b16565b610c3b565b6004805463ffffffff191663ffffffff928316179081905516919050565b60006401000000008210610c805760405162461bcd60e51b8152600401808060200182810382526026815260200180610ccb6026913960400191505060405180910390fd5b509056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657253616665436173743a2076616c756520646f65736e27742066697420696e2033322062697473a264697066735822122069a390d399cb5c2741b1efda2da4868a798bb32c8cb970aa304f2491223bd23c64736f6c634300060600330000000000000000000000003d2341adb2d31f1c5530cdc622016af293177ae0000000000000000000000000b0897686c545045afc77cf20ec7a532e3120e0f1
Deployed Bytecode
0x608060405234801561001057600080fd5b506004361061010b5760003560e01c80638678a7b2116100a25780639e317f12116100715780639e317f121461028e578063dc6cfe10146102ab578063ddca3f43146102d4578063e2d84e23146102dc578063f2fde38b146102e45761010b565b80638678a7b2146101f95780638da5cb5b1461022457806394985ddd146102485780639d2a5f981461026b5761010b565b806361728f39116100de57806361728f391461019b5780636309b773146101b557806369fe0e2d146101d4578063715018a6146101f15761010b565b80630d37b5371461011057806319c2b4c31461013b5780633a19b9bc1461015c5780635badbe4c14610193575b600080fd5b61011861030a565b604080516001600160a01b03909316835260208301919091528051918290030190f35b610143610331565b6040805163ffffffff9092168252519081900360200190f35b61017f6004803603602081101561017257600080fd5b503563ffffffff1661033d565b604080519115158252519081900360200190f35b610143610357565b6101a3610363565b60408051918252519081900360200190f35b6101d2600480360360208110156101cb57600080fd5b5035610369565b005b6101d2600480360360208110156101ea57600080fd5b50356103fc565b6101d261048f565b610201610531565b6040805163ffffffff938416815291909216602082015281519081900390910190f35b61022c61069e565b604080516001600160a01b039092168252519081900360200190f35b6101d26004803603604081101561025e57600080fd5b50803590602001356106ad565b6101a36004803603602081101561028157600080fd5b503563ffffffff16610738565b6101a3600480360360208110156102a457600080fd5b5035610750565b6101a3600480360360608110156102c157600080fd5b5080359060208101359060400135610762565b6101a3610924565b61022c61092a565b6101d2600480360360208110156102fa57600080fd5b50356001600160a01b031661094e565b6003547f000000000000000000000000b0897686c545045afc77cf20ec7a532e3120e0f191565b60045463ffffffff1690565b63ffffffff16600090815260056020526040902054151590565b60045463ffffffff1681565b60025481565b610371610a47565b6001546001600160a01b039081169116146103c1576040805162461bcd60e51b81526020600482018190526024820152600080516020610cab833981519152604482015290519081900360640190fd5b60028190556040805182815290517fd013f86c8346660ebf421351882cd1b3c2f91883092df1800264c656b0db0cc69181900360200190a150565b610404610a47565b6001546001600160a01b03908116911614610454576040805162461bcd60e51b81526020600482018190526024820152600080516020610cab833981519152604482015290519081900360640190fd5b60038190556040805182815290517f20461e09b8e557b77e107939f9ce6544698123aad0fc964ac5cc59b7df2e608f9181900360200190a150565b610497610a47565b6001546001600160a01b039081169116146104e7576040805162461bcd60e51b81526020600482018190526024820152600080516020610cab833981519152604482015290519081900360640190fd5b6001546040516000916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0908390a3600180546001600160a01b0319169055565b600080600061053e610a4b565b600354604080516323b872dd60e01b81523360048201523060248201526044810192909252514394509192506001600160a01b037f000000000000000000000000b0897686c545045afc77cf20ec7a532e3120e0f116916323b872dd916064808201926020929091908290030181600087803b1580156105bd57600080fd5b505af11580156105d1573d6000803e3d6000fd5b505050506040513d60208110156105e757600080fd5b505161063a576040805162461bcd60e51b815260206004820181905260248201527f524e47436861696e6c696e6b2f6665652d7472616e736665722d6661696c6564604482015290519081900360640190fd5b61064381610a54565b63ffffffff818116600081815260066020526040808220805463ffffffff1916948816949094179093559151929550339290917fcf635b20f2defc1e71326dc4f0b616fa676e29a5bae87da19fcaddc550b33f0391a3509091565b6001546001600160a01b031690565b336001600160a01b037f0000000000000000000000003d2341adb2d31f1c5530cdc622016af293177ae0161461072a576040805162461bcd60e51b815260206004820152601f60248201527f4f6e6c7920565246436f6f7264696e61746f722063616e2066756c66696c6c00604482015290519081900360640190fd5b6107348282610ac8565b5050565b63ffffffff1660009081526005602052604090205490565b60006020819052908152604090205481565b60007f000000000000000000000000b0897686c545045afc77cf20ec7a532e3120e0f16001600160a01b0316634000aea07f0000000000000000000000003d2341adb2d31f1c5530cdc622016af293177ae085878660405160200180838152602001828152602001925050506040516020818303038152906040526040518463ffffffff1660e01b815260040180846001600160a01b03166001600160a01b0316815260200183815260200180602001828103825283818151815260200191508051906020019080838360005b8381101561084757818101518382015260200161082f565b50505050905090810190601f1680156108745780820380516001836020036101000a031916815260200191505b50945050505050602060405180830381600087803b15801561089557600080fd5b505af11580156108a9573d6000803e3d6000fd5b505050506040513d60208110156108bf57600080fd5b50506000848152602081905260408120546108df90869085903090610b24565b60008681526020819052604090205490915061090290600163ffffffff610b6b16565b60008681526020819052604090205561091b8582610bcc565b95945050505050565b60035481565b7f000000000000000000000000b0897686c545045afc77cf20ec7a532e3120e0f190565b610956610a47565b6001546001600160a01b039081169116146109a6576040805162461bcd60e51b81526020600482018190526024820152600080516020610cab833981519152604482015290519081900360640190fd5b6001600160a01b0381166109eb5760405162461bcd60e51b8152600401808060200182810382526026815260200180610c856026913960400191505060405180910390fd5b6001546040516001600160a01b038084169216907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a3600180546001600160a01b0319166001600160a01b0392909216919091179055565b3390565b60001943014090565b6000610a5e610bf8565b90506000610a7160025460035485610762565b600081815260076020526040808220805463ffffffff191663ffffffff87169081179091559051929350839290917ff7617d06180c24c92bad8c8436c3ae97409a09e1f5655da6c0807f50c5f9674891a350919050565b60008281526007602090815260408083205463ffffffff1680845260058352928190208490558051848152905183927f629394f18de7accce1179c28c39be59503a57cbcf45980a2772743b041b36271928290030190a2505050565b60408051602080820196909652808201949094526001600160a01b039290921660608401526080808401919091528151808403909101815260a09092019052805191012090565b600082820183811015610bc5576040805162461bcd60e51b815260206004820152601b60248201527f536166654d6174683a206164646974696f6e206f766572666c6f770000000000604482015290519081900360640190fd5b9392505050565b604080516020808201949094528082019290925280518083038201815260609092019052805191012090565b600454600090610c1d90610c189063ffffffff90811690600190610b6b16565b610c3b565b6004805463ffffffff191663ffffffff928316179081905516919050565b60006401000000008210610c805760405162461bcd60e51b8152600401808060200182810382526026815260200180610ccb6026913960400191505060405180910390fd5b509056fe4f776e61626c653a206e6577206f776e657220697320746865207a65726f20616464726573734f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657253616665436173743a2076616c756520646f65736e27742066697420696e2033322062697473a264697066735822122069a390d399cb5c2741b1efda2da4868a798bb32c8cb970aa304f2491223bd23c64736f6c63430006060033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000003d2341adb2d31f1c5530cdc622016af293177ae0000000000000000000000000b0897686c545045afc77cf20ec7a532e3120e0f1
-----Decoded View---------------
Arg [0] : _vrfCoordinator (address): 0x3d2341ADb2D31f1c5530cDC622016af293177AE0
Arg [1] : _link (address): 0xb0897686c545045aFc77CF20eC7A532E3120E0F1
-----Encoded View---------------
2 Constructor Arguments found :
Arg [0] : 0000000000000000000000003d2341adb2d31f1c5530cdc622016af293177ae0
Arg [1] : 000000000000000000000000b0897686c545045afc77cf20ec7a532e3120e0f1
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.