Creation and Deployment of VRF-Consumer Contract
Last updated
Last updated
Note:- Steps will remain the same for mainnet deployment as well except the contract deployment in the 3rd step.
For this demonstration, utilize the vrf_subscription_consumer_xdc_apothem.sol contract. This contract imports dependencies including VRFConsumerBaseV2.sol, VRFCoordinatorV2Interface.sol, and ConfirmedOwner.sol.
The contract incorporates preconfigured values for requisite request parameters such as vrfCoordinator address, gas lane keyHash, callbackGasLimit, requestConfirmations, and the number of random words, numWords. For this scenario, specify only the subscriptionId during contract deployment.
Open and copy the vrf_subscription_consumer_xdc_apothem.sol contract to remix for apothem, and for mainnet open the following contract vrf_subscription_consumer_xdc_mainnet.sol in remix.
Compile the vrf_subscription_consumer_xdc_apothem contract on the Compile tab in Remix.
Configure deployment settings. Select the Injected Provider environment and the vrf_subscription_consumer_xdc_apothem contract from the contract list on the Deploy tab in Remix. Specify your subscriptionId to allow the constructor to set it.
Click the Deploy button to initiate on-chain deployment of your contract. MetaMask prompts confirmation of the transaction.
Upon contract deployment, copy the contract address from the Deployed Contracts list in Remix. Subsequently, add this address as an approved consuming contract on your subscription account before requesting randomness from VRF.
Access the Subscription Manager and select the ID of your new subscription under the My Subscriptions list to view subscription details.
Under the Consumers section, click Add consumer.
Input the address of your recently deployed consuming contract and click Add consumer. MetaMask prompts confirmation of the transaction.
Deployment and Approval of Example Contract
Your example contract is now deployed and approved for utilization of your subscription balance to facilitate VRF requests. Next, proceed to request random values from Plugin VRF.