️ You might be viewing the VRF v2 information.
In case you are utilizing v1, see the VRF v1 information.
Chainlink VRF (Verifiable Random Perform) is a provably honest and verifiable random quantity generator (RNG) that allows sensible contracts to entry random values with out compromising safety or usability.
Desk of contents
- Supported networks
- Subscription billing
For every request, Chainlink VRF generates a number of random values and cryptographic proof of how these values have been decided. The proof is printed and verified on-chain earlier than any consuming purposes can use it. This course of ensures that outcomes can’t be tampered with or manipulated by any single entity together with oracle operators, miners, customers, or sensible contract builders.
Use Chainlink VRF to construct dependable sensible contracts for any purposes that depend on unpredictable outcomes:
- Constructing blockchain video games and NFTs.
- Random task of duties and assets. For instance, randomly assigning judges to instances.
- Selecting a consultant pattern for consensus mechanisms.
To be taught extra about the advantages of Chainlink VRF v2, see our weblog put up Chainlink VRF v2 Is Now Dwell on Mainnet. For assist along with your particular use case, contact us to attach with certainly one of our Options Architects. You may also ask questions on Chainlink VRF on Stack Overflow.
Chainlink VRF v2 is at the moment out there on the next networks:
- Rinkeby testnet
- BNB Chain
See the Contract Addresses web page for a whole listing of coordinator addresses and gasoline value limits.
To be taught when VRF v2 turns into out there on extra networks, observe us on Twitter or join our mailing listing.
VRF v2 requests obtain funding from subscription accounts. The Subscription Supervisor allows you to create an account and pre-pay for VRF v2, so you do not present funding every time your software requests randomness. This reduces the whole gasoline value to make use of VRF v2. It additionally offers a easy technique to fund your use of Chainlink merchandise from a single location, so you do not have to handle a number of wallets throughout a number of totally different programs and purposes.
Subscriptions have the next core ideas:
- Subscription accounts: An account that holds LINK tokens and makes them out there to fund requests to Chainlink VRF v2 coordinators.
- Subscription proprietor: The pockets tackle that creates and manages a subscription account. Any account can add LINK to the subscription stability, however solely the proprietor can add accepted shoppers or withdraw funds.
- Shoppers: Contracts which can be accepted to make use of funding out of your subscription account.
- Subscription stability: The quantity of LINK maintained in your subscription account. Requests from client contracts will proceed to be funded till the stability runs out, so you should definitely keep enough funds in your subscription stability to pay for the requests and preserve your purposes operating.
For Chainlink VRF v2 to satisfy your requests, it’s essential to keep a enough quantity of LINK in your subscription stability. Fuel value calculation contains the next variables:
Fuel value: The present gasoline value, which fluctuates relying on community situations
Callback gasoline: The quantity of gasoline used for the callback request that returns your requested random values
Verification gasoline: The quantity of gasoline used to confirm randomness on-chain
These variables rely upon present community situations, your specified restrict on callback gasoline, and the variety of random values in your request. The price of every request is remaining solely after the transaction is full, however you outline the boundaries you’re prepared to spend for the request with the next variables:
Fuel lane: The utmost gasoline value you’re prepared to pay for a request in wei. Outline this restrict by specifying the suitable keyHash in your request. The bounds of every gasoline lane are vital for dealing with gasoline value spikes when Chainlink VRF bumps the gasoline value to satisfy your request rapidly.
Callback gasoline restrict: Specifies the utmost quantity of gasoline you’re prepared to spend on the callback request. Outline this restrict by specifying the callbackGasLimit worth in your request.
Requests to Chainlink VRF v2 observe the Request & Obtain Information cycle. The VRF coordinator processes the request and determines the ultimate cost to your subscription utilizing the next steps:
You submit your request with a specified gasoline lane keyHash and the callbackGasLimit. In case your request is pressing, specify a gasoline lane with the next gasoline value restrict. The callbackGasLimit relies on the scale of your request. Usually, a restrict of 100,000 gasoline is acceptable. Verification gasoline has a tough higher restrict of 200,000 gasoline.
The coordinator begins the transaction and bumps the gasoline value till the transaction is full. The coordinator is not going to exceed the gasoline value restrict of your chosen gasoline lane. In case your request can’t be accomplished at your specified gasoline restrict, resubmit the request with a unique gasoline lane or wait till gasoline costs fall beneath your present gasoline lane limits.
The responding Chainlink oracle verifies your random values on-chain and completes the callback to your contract with the random values.
After the request is full, the ultimate gasoline value is recorded based mostly on how a lot gasoline is required for the verification and callback. The overall gasoline value in wei in your request makes use of the next method:
(Fuel value * (Verification gasoline + Callback gasoline)) = whole gasoline value
The overall gasoline value is transformed to LINK utilizing the ETH/LINK knowledge feed. Within the unlikely occasion that the information feed is unavailable, the VRF coordinator makes use of the fallbackWeiPerUnitLink worth for the conversion as a substitute. The fallbackWeiPerUnitLink worth is outlined within the coordinator contract in your chosen community.
The LINK premium is added to the whole gasoline value. The premium is outlined within the coordinator contract with the fulfillmentFlatFeeLinkPPMTier1 parameter in millionths of LINK.
(whole gasoline value + LINK premium) = whole request value
The overall request value is charged to your subscription stability.
Chainlink VRF v2 has some subscription limits and coordinator contract limits.
Every subscription has the next limits:
Every subscription should keep a minimal stability to fund requests from client contracts. In case your stability is beneath that minimal, your requests stay pending for as much as 24 hours earlier than they expire. After you add enough LINK to a subscription, pending requests robotically course of so long as they haven’t expired.
The minimal subscription stability have to be enough for every new client contract that you just add to a subscription. The required dimension of the minimal stability relies on the gasoline lane and the scale of the request that the buyer contract makes. For instance, a client contract that requests one random worth would require a smaller minimal stability than a client contract that requests 50 random values. Usually, you possibly can estimate the required minimal LINK stability utilizing the next method the place max verification gasoline is all the time 200,000.
((Fuel lane most * (Max verification gasoline + Callback gasoline restrict)) / (ETH to LINK value)) + LINK premium = Minimal LINK
Every subscription helps as much as 100 client contracts. In the event you want greater than 100 shoppers, create a number of subscriptions.
Coordinator contract limits
You’ll be able to see the configuration for every community on the Contract Addresses web page. You may also view the total configuration for every coordinator contract instantly in Etherscan. For example, view the Ethereum Mainnet VRF v2 coordinator contract configuration.
- Every coordinator has a MAX_NUM_WORDS parameter that limits the utmost variety of random values you possibly can obtain in every request.
- Every coordinator has a maxGasLimit parameter, which is the utmost allowed callbackGasLimit worth in your requests.
- You need to specify a enough callbackGasLimit to fund the callback request to your client contract. This relies on the variety of random values you request and the way you course of them in your fulfillRandomWords() perform. In case your callbackGasLimit just isn’t enough, the callback fails however your subscription continues to be charged for the work completed to generate your requested random values.