Documentation
Plugins

Chainlink VRF

BuildBear Chainlink VRF Plugin enables seamless integration of Chainlink VRF for true randomness in smart contracts.

Overview

The BuildBear Chainlink VRF Plugin allows developers to seamlessly integrate Chainlink VRF into their development workflow for random number generation without the need for mock setups. For example, if you have a Lottery Smart Contract that depends on a random number from Chainlink, you can install the Chainlink VRF plugin and call the Chainlink contracts as you would on the Mainnet—no need to set up any mock contracts or calls.

For detailed documentation on how to use Chainlink VRF v2.5, please refer to the Chainlink Documentation.

Features

  • Subscription Method Support - Manage multiple consumer contracts with a single subscription funded with LINK tokens.
  • Existing & New Subscription Support - Use your current Chainlink VRF subscription or create a new one with ease.
  • Multi-Network Compatibility - Supported networks include Ethereum, Arbitrum, Avalanche, BNB, and Polygon.

How to Use

Install the Plugin

  1. Log in to your BuildBear account and navigate to the Plugin Marketplace.
  2. Search for the "Chainlink VRF" Plugin and click "Install".

Plugin Installation

Step 2: Verify Installation

Ensure the plugin appears as installed in the marketplace or under the 'Installed' tab.

Option 1: Use an Existing Subscription

If you have an existing Chainlink VRF subscription on a supported mainnet or testnet, you can use your current Subscription ID.

  • If the subscription is already funded on the mainnet, your smart contract calls will work on BuildBear Sandboxes without modifications.
  • If the subscription is not funded, you can fund it using LINK tokens just as you would on the mainnet. You can also use the BuildBear Faucet to get LINK tokens easily. For your convenience, you can refer to the Fund Subscription#L33 section in this script.

Option 2: Create a New Subscription

If you need to create a new subscription, follow these steps:

  1. Call createSubscription() in the VRF Coordinator Contract in your sandbox to get a Subscription ID.
  2. Fund the subscription with LINK tokens by calling transferAndCall() to enable random number requests.

You can follow this script to automate the steps.

Note:

  • The account must have a sufficient LINK balance. You can use the BuildBear Faucet to obtain LINK tokens.
  • The value parameter in transferAndCall should be in the smallest denomination of LINK, called Juel (1 LINK = 1e18 Juel).
  • The data parameter in transferAndCall must be the Subscription ID in ABI-encoded form.
  1. Deploy the consumer contract and add it to the VRF Coordinator.
  2. Request random words as you would on the Mainnet.

Conclusion

Install the Chainlink VRF plugin in your sandbox to effortlessly get random values for your smart contracts, just as you would on the mainnet or any supported network.