New: Explore our latest Web3 innovations.Learn More about Ancilar Web3 services

Chainlink VRF V2: Subscription, Gas, and Fulfillment Guide

Blockchain
2024-01-17
Author:Jyotvir
Chainlink VRF V2: Subscription, Gas, and Fulfillment Guide

Integrate Chainlink VRF V2 with the subscription model, configure gas lanes and callbackGasLimit, and implement fulfillRandomWords correctly. Build now.

Frequently Asked Questions

Chainlink VRF V2 does not enforce a protocol-level minimum balance on the subscription itself, but the coordinator will reject a fulfillment request if the subscription balance is insufficient to cover the estimated callback cost at current gas prices. As a practical baseline, Chainlink's documentation recommends funding a subscription with at least 2 LINK on Ethereum mainnet before making your first request, and topping it up regularly if your contract makes frequent requests.
The callbackGasLimit parameter sets the maximum amount of gas the VRF coordinator will forward to your fulfillRandomWords() function when delivering randomness. If your callback logic exceeds this limit, the transaction reverts at the coordinator level and the random words are never delivered. You must estimate the gas your callback consumes, add a 20-30% buffer, and set callbackGasLimit accordingly. The maximum permitted value is 2,500,000 gas on Ethereum mainnet as of the V2 launch.
A single requestRandomWords() call can request up to 500 random words (numWords parameter). All requested words are generated and delivered in a single fulfillRandomWords() callback. Batching multiple words into one request is far more gas-efficient than making multiple individual requests because the LINK cost and the commit-reveal delay (minimum 3 blocks on Ethereum mainnet) are both incurred only once per request, not once per word.
In the subscription model, you pre-fund a central subscription account with LINK and add consumer contract addresses to it. Multiple contracts share one subscription balance, and LINK is deducted per fulfilled request. In the direct funding model (available via VRFV2Wrapper), your consumer contract itself holds LINK and pays per request without pre-registration. The subscription model is more gas-efficient for high-volume applications because it avoids per-request LINK transfer overhead.
Chainlink VRF V2 uses a commit-reveal scheme across two transactions to prevent manipulation. In the first transaction, your contract emits a randomness request with a seed. The VRF oracle node commits to a proof before seeing the block hash of that transaction's block. The second transaction delivers the random output along with the cryptographic proof. Because the oracle cannot know the future block hash when it commits, neither miners nor the oracle can bias the output. The requestConfirmations parameter controls how many blocks must pass between the two transactions.

Don't Miss What's Next

Subscribe to newsletter

Tags:

Chainlink VRF

VRF V2

Subscription Model

On-Chain Randomness

Smart Contracts

Solidity

Gas Optimization

Oracle

Get in Touch

Our team will get back to you within 24 hours.

A clear proven process, that delivers

End of Scroll. Start of Discovery.

You've seen our ideas - now go deeper.
Discover more insights, tutorials, and innovations shaping Web3.