Chainlink VRF: Subscription ID Exceeds uint64 Limits

I'm working on a smart contract using Chainlink VRF (Verifiable Random Function) on the Ethereum Sepolia network. According to the documentation and examples, the subscription ID should be a uint64. However, the subscription ID I received is much larger than what uint64 can hold.

Details: Network: Ethereum Sepolia, Subscription ID Provided: 55908212076489414356763290517690794428993368234670108884296656046224328470330, Chainlink VRF Contract Version: 2.5 Code Example: Here is the relevant part of my Solidity contract:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol";
import "@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract Lottery is VRFConsumerBaseV2, ReentrancyGuard {
    VRFCoordinatorV2Interface COORDINATOR;
    LinkTokenInterface LINKTOKEN;

    uint64 s_subscriptionId;
    address vrfCoordinator;
    bytes32 keyHash;
    uint32 callbackGasLimit = 100000;
    uint16 requestConfirmations = 3;
    uint32 numWords = 1;
    uint256[] public s_randomWords;
    uint256 public s_requestId;

    constructor(
        address _vrfCoordinator,
        address _linkToken,
        bytes32 _keyHash,
        uint64 _subscriptionId
    ) VRFConsumerBaseV2(_vrfCoordinator) {
        vrfCoordinator = _vrfCoordinator;
        LINKTOKEN = LinkTokenInterface(_linkToken);
        COORDINATOR = VRFCoordinatorV2Interface(_vrfCoordinator);
        keyHash = _keyHash;
        s_subscriptionId = _subscriptionId;
    }

    function requestRandomWinner() public onlyManager onlyAfterLotteryEnd {
        require(LINKTOKEN.balanceOf(address(this)) >= 0.1 * 10**18, "Not enough LINK - fill contract with faucet");
        s_requestId = COORDINATOR.requestRandomWords(
            keyHash,
            s_subscriptionId,
            requestConfirmations,
            callbackGasLimit,
            numWords
        );
    }

    function fulfillRandomWords(uint256, uint256[] memory randomWords) internal override nonReentrant {
        randomResult = randomWords[0];
        // Additional logic
    }
}

I tried to deploy a Lottery smart contract that integrates Chainlink VRF to pick a random winner. I expected the subscription ID provided by Chainlink to fit within the uint64 range, as required by the requestRandomWords function in the contract. Instead, the provided subscription ID was much larger, causing an "Error encoding arguments: value out-of-bounds" during deployment.

Steps Taken: Generated Subscription ID: Created a new Chainlink VRF subscription on the Ethereum Sepolia network. Updated Contract: Updated the smart contract with the new subscription ID and other necessary parameters. Deployment Attempt: Attempted to deploy the contract on the Ethereum Sepolia testnet using Remix IDE. Expected Result: The contract should have deployed successfully, allowing me to use the Chainlink VRF to generate random numbers.

Actual Result: Received an error indicating the subscription ID value was out-of-bounds for uint64.

Error encoding arguments: Error: value out-of-bounds (argument=null, value="55908212076489414356763290517690794428993368234670108884296656046224328470330", code=INVALID_ARGUMENT, version=abi/5.7.0) ```

This discrepancy prevents me from deploying the contract and utilizing Chainlink VRF as intended

Upvotes: 1

Views: 170

Answers (2)

Frank Kong
Frank Kong

Reputation: 1082

Chainlink VRF version was upgraded from 2.0 to 2.5 in June 2024.

The subscription you created on VRF app is VRF version 2.5 while the subscription you want to use should be VRF version 2.0. The subId data type is uint256 instead of uint64 in version 2.5.

You need to use the consumer contract with VRF2.5. Please check this page to see how to migrate from VRF2.0 to 2.5.

Upvotes: 1

Ali Murtaza
Ali Murtaza

Reputation: 560

You are using the old code. Now in the Chainlink VRF version 2.5, the subscription ID's type is uint256.

You can check out the latest code example here.

Upvotes: 0

Related Questions