RNGServiceChainlinkV2
This contract implements a service that allows it to work with the Chainlink V2 to request randomness.
Write methods description
claimOwnership()
Allows the pendingOwner
address to claim the owner role. This function is only callable by the pendingOwner
.
initialize()
Allows to initialize the contract during the deployment.
Parameters:
_owner
address
An owner of the contract.
_vrfCoordinator
address
An address of the VRF Coordinator.
_subscriptionId
uint64
Chainlink VRF subscription ID.
_keyHash
bytes32
Hash of the public key used to verify the VRF proof.
rawFulfillRandomWords()
Handles the VRF response. This function is only callable by the VRF Coordinator.
Parameters:
_requestId
uint256
The ID initially returned by requestRandomWords
method.
_randomWords
uint256[]
The VRF output expanded to the requested number of words.
renounceOwnership()
Leaves the contract without owner. It will not be possible to call the owner's functions anymore. Can only be called by the current owner. The method does not take any parameters. Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.
requestRandomNumbers()
Sends a request for a random numbers to the 3rd-party service. Some services will complete the request immediately, others may have a time-delay. Some services require payment in the form of a token, such as LINK for Chainlink VRF. The calling contract should lock
all activity until the result is available via the requestId
. This function is only callable by the manager.
Parameters:
_numWords
uint32
An amount of random numbers to request.
Return:
_requestId
uint32
The ID of the request used to get the results of the RNG service.
_lockBlock
uint32
The block number at which the RNG service will start generating time-delayed randomness.
setKeyHash()
Sets Chainlink VRF key hash. This function is only callable by the owner.
Parameters:
_keyHash
bytes32
Chainlink VRF key hash.
setManager()
Allows the owner to give the manager role to an address. The manager role has access to the functions with the modified onlyManagerOrOwner.
Parameters:
_newManager
address
A new manager address.
setSubscriptionId()
Sets Chainlink VRF subscription ID associated with this contract. This function is only callable by the owner.
Parameters:
_subscriptionId
uint64
Chainlink VRF subscription ID.
transferOwnership()
Transfers ownership of the contract to a _pendingOwner
. Can only be called by the current owner.
Parameters:
_newOwner
address
An account that will become the _pendingOwner
.
Read methods description
getKeyHash()
Gets Chainlink VRF key hash associated with this service contract. A key hash is an identifier that maps to a job and a private key on the VRF service and that represents a specified gas lane. If your request is urgent, specify a gas lane with a higher gas price limit.
Return:
_keyHash
bytes32
Chainlink VRF key hash.
getLastRequestId()
Gets the last request ID used by the RNG service.
Return:
_lastRequestId
uint32
The last request ID used in the last request.
getRandomNumbers()
Gets an array of random numbers produced by the 3rd-party service.
Parameters:
_internalRequestId
uint32
The ID of the request used to get the results of the RNG service.
Return:
_randomNumbers
uint256[]
An array of random numbers.
getRequestFee()
Gets the fee for making a request against an RNG service.
Return:
_feeToken
address
The address of the token that is used to pay fees.
_fee
uint256
The fee required to be paid to make a request.
getSubscriptionId()
Gets Chainlink VRF subscription ID associated with this contract.
Return:
_subscriptionId
uint64
Chainlink VRF subscription ID.
getVrfCoordinator()
Gets Chainlink VRF coordinator contract address associated with this contract.
Return:
_vrfCoordinator
address
Chainlink VRF coordinator address.
isRequestCompleted()
Checks if the request for randomness from the 3rd-party service has completed. For time-delayed requests, this function is used to check/confirm completion.
Parameters:
_internalRequestId
uint32
The ID of the request used to get the results of the RNG service.
Return:
_isRequestCompleted
bool
true
if the request has completed and a random number is available, false
otherwise.
manager()
Gets a manager address that was granted exclusive access to specific functions with the modifier onlyManagerOrOwner.
Return:
_manager
address
A manager address.
owner()
Gets an owner address that was granted exclusive access to specific functions with the modifier onlyOwner
.
Return:
_owner
address
An owner address.
pendingOwner()
Gets an address that can claim the owner role. It is used to transfer the ownership.
Return:
_pendingOwner
address
A pending owner address.
Last updated