API reference for
|constructor||Initialize your consumer contract.|
Initialize your consumer contract.
constructor(address _vrfCoordinator, address _link) public
_vrfCoordinator: Address of the Chainlink VRF Coordinator. See Chainlink VRF Addresses for details.
_link: Address of the LINK token. See LINK Token Addresses for details.
Make a request to the VRF coordinator.
function requestRandomness(bytes32 _keyHash, uint256 _fee, uint256 _seed) public returns (bytes32 requestId)
_keyHash: The public key against which randomness is generated. See Chainlink VRF Addresses for details.
_fee: The fee, in LINK, for the request. Specified by the oracle.
_seed: This is the seed from which output randomness is determined. Provided by you.
RETURN: The ID unique to a single request.
️ Choosing a seed
It is vital that you choose a seed that is difficult to anticipate. See Choosing a Seed for more details.
Called by VRFCoordinator when it receives a valid VRF proof. Override this function to act upon the random number generated by Chainlink VRF.
function fulfillRandomness(bytes32 requestId, uint256 randomness) external virtual;
requestId: The Id initially returned by
randomness: Random number generated by Chainlink VRF.
The source of your seeds should be hard for anyone to influence or predict. Any party who can influence them could in principle collude with the oracle (who can instantly compute the VRF output for any given seed) to bias the outcomes from your contract in their favor.
For example, the block hash is a natural choice of seed for many applications, but miners in control of a substantial fraction of hashing power and with access to VRF outputs could check the result of prospective block hashes as they are mined, and decide not to publish a block if they don't like the outcome it will lead to.
On the other hand, using block hashes as the seed makes it particularly easy to estimate the economic cost to a miner for this kind of cheating (namely, the block reward and transaction fees they forgo by refraining from publishing a block.)
Chainlink VRF provides powerful security guarantees and is easy to integrate. However, smart contract security is a nuanced topic. If you have specific questions about your integration, please contact [email protected]
Updated 21 days ago