client makes calls to get data from an oracle like Chainlink
ChainLink VRF
Chainlink VRF v2 is currently available on the following networks:
Ethereum:
BNB Chain
Gas price: The current gas price, which fluctuates depending on network conditions
Callback gas: The amount of gas used for the callback request that returns your requested random values
Verification gas: The amount of gas used to verify randomness on-chain
Each subscription has the following limits:
Each subscription must maintain a minimum balance to fund requests from consumer contracts. If your balance is below that minimum, your requests remain pending for up to 24 hours before they expire. After you add sufficient LINK to a subscription, pending requests automatically process as long as they have not expired.
The minimum subscription balance must be sufficient for each new consumer contract that you add to a subscription. The required size of the minimum balance depends on the gas lane and the size of the request that the consumer contract makes. For example, a consumer contract that requests one random value will require a smaller minimum balance than a consumer contract that requests 50 random values. In general, you can estimate the required minimum LINK balance using the following formula where max verification gas is always 200,000.
((Gas lane maximum * (Max verification gas + Callback gas limit)) / (ETH to LINK price)) + LINK premium = Minimum LINK
Each subscription supports up to 100 consumer contracts. If you need more than 100 consumers, create multiple subscriptions.
You can see the configuration for each network on the Contract Addresses page. You can also view the full configuration for each coordinator contract directly in Etherscan. As an example, view the Ethereum Mainnet VRF v2 coordinator contract configuration.
MAX_NUM_WORDS
parameter that limits the maximum number of random values you can receive in each request.maxGasLimit
parameter, which is the maximum allowed callbackGasLimit
value for your requests.callbackGasLimit
to fund the callback request to your consumer contract. This depends on the number of random values you request and how you process them in your fulfillRandomWords()
function. If your callbackGasLimit
is not sufficient, the callback fails but your subscription is still charged for the work done to generate your requested random values.This guide assumes that you know how to create and deploy smart contracts on Ethereum testnets using the following tools:
For this example, create a new subscription on the Rinkeby testnet.
bitwise operators: 64bits
1st===0, 31bits
2nd===32, 63bits
3rd===64, 95bits
4th===96, 127bits
5th===128, 15bits
6th===160, 191bits
$ git clone <https://github.com/pappas999/chainlink-hardhat-box>
$ cd chainlink-hardhat-box
$ yarn
$ npx hardhat deploy
// USING DATA FEEDS
$ npx hardhat read-price-feed --contract 0x0ef1181768A99E522FB5535fA2e0D172B36d3479
$ npx hardhat fund-link --contract 0xc719F4B720cB7cBcabB09dF0040b47f3F9CE6a58
$ npx hardhat request-data --contract 0xc719F4B720cB7cBcabB09dF0040b47f3F9CE6a58
$ npx hardhat read-data --contract 0xc719F4B720cB7cBcabB09dF0040b47f3F9CE6a58
// using