logoAcademy

Orchestrating VRF Requests Over Multiple Chains (Wrapper)

Learn how the CrossChainVRFWrapper contract on a Chainlink-supported L1 handles cross-chain requests for VRF.

The CrossChainVRFWrapper contract plays a critical role in handling requests for randomness from an unsupported L1. It is deployed on a Chainlink-supported network (like Avalanche Fuji) and serves as the intermediary that interacts with Chainlink VRF to request random words.

Here’s how it functions as the provider for VRF services:

Receives Cross-Chain Messages

When the CrossChainVRFConsumer on the unsupported L1 initiates a request for randomness, it sends a cross-chain message via the TeleporterMessenger to the CrossChainVRFWrapper on the supported network.

The CrossChainVRFWrapper verifies that the request came from an authorized address. This is essential to ensure that only verified consumers can request randomness.

Upon receiving a valid request, the VRFWrapper calls Chainlink VRF and sends the request with the required parameters, such as the number of random words, request confirmations, and gas limits.

The CrossChainVRFWrapper keeps track of all pending requests using a mapping, associating each request ID with its destination (the L1 where the CrossChainVRFConsumer resides). This ensures that the random words are returned to the correct destination once fulfilled.

When Chainlink VRF fulfills the randomness request, the CrossChainVRFWrapper receives the random words through a callback function. This ensures that the request has been successfully processed.

After receiving the random words, the CrossChainVRFWrapper encodes the result and sends it back as a cross-chain message to the CrossChainVRFConsumer on the unsupported L1. This is done using the TeleporterMessenger.

In summary, the CrossChainVRFWrapper contract acts as the bridge between the unsupported L1 and Chainlink’s VRF services, ensuring that random words are requested, fulfilled, and delivered back across chains efficiently.

On this page