Lesson 9: Error: value out-of-bounds (argument="subscriptionId"...). How create a subscriptionId V2 instead V2.5? #6621
-
I was trying to deploy my Raffle.sol to Sepolia network, but the following error appears: Error: value out-of-bounds (argument="subscriptionId", value="57523992536066914636542733918698497913286620907923606939974052550738514442581", code=INVALID_ARGUMENT, version=abi/5.7.0) I know where the error is but I don't know how to solution, so the scripts are the following: const { network, ethers } = require("hardhat")
const { developmentChains, networkConfig } = require("../helper-hardhat-config")
const { verify } = require("../utils/verify")
const VRF_SUB_FUND_AMOUNT = ethers.parseEther("30")
module.exports = async function ({ getNamedAccounts, deployments }) {
const { deploy, log } = deployments
const { deployer } = await getNamedAccounts()
const chainId = network.config.chainId
let vrfCoordinatorV2Address, subscriptionId
if (developmentChains.includes(network.name)) {
const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
vrfCoordinatorV2Address = vrfCoordinatorV2Mock.target
const transactionResponse = await vrfCoordinatorV2Mock.createSubscription()
const transactionReceipt = await transactionResponse.wait(1)
subscriptionId = transactionReceipt.logs[0].args.subId
await vrfCoordinatorV2Mock.fundSubscription(subscriptionId, VRF_SUB_FUND_AMOUNT)
} else {
vrfCoordinatorV2Address = networkConfig[chainId]["vrfCoordinatorV2"]
subscriptionId = networkConfig[chainId]["subscriptionId"]
}
const entranceFee = networkConfig[chainId]["entranceFee"]
const gasLane = networkConfig[chainId]["gasLane"]
const callbackGasLimit = networkConfig[chainId]["callbackGasLimit"]
const interval = networkConfig[chainId]["interval"]
const args = [
vrfCoordinatorV2Address,
entranceFee,
gasLane,
subscriptionId,
callbackGasLimit,
interval,
]
const raffle = await deploy("Raffle", {
from: deployer,
args: args,
log: true,
waitConfirmations: network.config.blockConfirmations || 1,
})
if (chainId == 31337) {
const vrfCoordinatorV2Mock = await ethers.getContract("VRFCoordinatorV2Mock")
await vrfCoordinatorV2Mock.addConsumer(Number(subscriptionId), raffle.address)
log("Adding consumer...")
log("Consumer added!")
}
if (!developmentChains.includes(network.name) && process.env.ETHERSCAN_API_KEY) {
log("Verifying...")
await verify(raffle.address, args)
}
log("---------------------------------------------------")
}
module.exports.tags = ["all", "raffle"] helper-hardhat-config.js const { ethers } = require("hardhat")
const networkConfig = {
11155111: {
name: "sepolia",
vrfCoordinatorV2: "0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625",
entranceFee: ethers.parseEther("0.01"),
gasLane: "0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c",
subscriptionId:
"57523992536066914636542733918698497913286620907923606939974052550738514442581",
callbackGasLimit: "500000",
interval: "30",
},
31337: {
name: "hardhat",
entranceFee: ethers.parseEther("0.01"),
gasLane: "0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c",
callbackGasLimit: "500000",
interval: "30",
},
}
const developmentChains = ["hardhat", "localhost"]
module.exports = {
networkConfig,
developmentChains,
} So, the problem is that the subscriptionId that Chainlink gave me is so much longer than an uint64; how can I create a subscription V2 instead V2.5? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
You can create a subscription V2 from the contract (in Sepolia): |
Beta Was this translation helpful? Give feedback.
-
you can click this two links below to change the subscriptionId from uint64 to uint256. |
Beta Was this translation helpful? Give feedback.
-
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// import "@chainlink/contracts/src/v0.8/vrf/interfaces/VRFCoordinatorV2Interface.sol";
import "@chainlink/contracts/src/v0.8/automation/AutomationCompatible.sol";
import {VRFConsumerBaseV2Plus} from "@chainlink/contracts/src/v0.8/vrf/dev/VRFConsumerBaseV2Plus.sol";
import {VRFV2PlusClient} from "@chainlink/contracts/src/v0.8/vrf/dev/libraries/VRFV2PlusClient.sol";
error Raffle__NotEnoughETHEntered();
error Raffle__TransferFailed();
error Raffle__NotOpen();
contract Raffle is VRFConsumerBaseV2Plus, AutomationCompatibleInterface {
enum RaffleState {
OPEN,
PENDING
}
address payable[] private s_players;
address payable private s_recentWinner;
RaffleState private s_raffleState;
uint256 private s_lastTimeStamp;
uint256 private immutable i_interval;
bytes32 private immutable i_gasLane;
uint256 private immutable i_entranceFee;
uint256 private immutable i_subscriptionId;
uint32 private immutable i_callbackGasLimit;
uint16 private constant REQUEST_CONFIRMATIONS = 3;
uint32 private constant NUM_WORDS = 1;
event RaffleEnter(address indexed player);
event RequestedRaffleWinner(uint256 indexed requestId);
event WinnerPicked(address indexed winner);
constructor(
address vrfCoordinatorV2,
uint256 entranceFee,
bytes32 gasLane,
uint256 subscriptionId,
uint32 callbackGasLimit,
uint256 interval
) VRFConsumerBaseV2Plus(vrfCoordinatorV2) {
i_entranceFee = entranceFee;
i_gasLane = gasLane;
i_subscriptionId = subscriptionId;
i_callbackGasLimit = callbackGasLimit;
s_raffleState = RaffleState.OPEN;
s_lastTimeStamp = block.timestamp;
i_interval = interval;
}
function enterRaffle() public payable {
if (msg.value < i_entranceFee) revert Raffle__NotEnoughETHEntered();
if (s_raffleState != RaffleState.OPEN) revert Raffle__NotOpen();
s_players.push(payable(msg.sender));
emit RaffleEnter(msg.sender);
}
function checkUpkeep(
bytes calldata /** checkData*/
) external view override returns (bool upkeepNeeded, bytes memory /* performData */) {
bool isOpen = (s_raffleState == RaffleState.OPEN);
bool timePassed = ((block.timestamp - s_lastTimeStamp) > i_interval);
bool hasPlayers = s_players.length > 0;
bool hasBalance = address(this).balance > 0;
upkeepNeeded = isOpen && timePassed && hasPlayers && hasBalance;
}
function performUpkeep(bytes calldata /** performData */) external override {
s_raffleState = RaffleState.PENDING;
uint256 requestId = s_vrfCoordinator.requestRandomWords(
VRFV2PlusClient.RandomWordsRequest({
keyHash: i_gasLane,
subId: i_subscriptionId,
requestConfirmations: REQUEST_CONFIRMATIONS,
callbackGasLimit: i_callbackGasLimit,
numWords: NUM_WORDS,
extraArgs: VRFV2PlusClient._argsToBytes(
VRFV2PlusClient.ExtraArgsV1({nativePayment: false})
)
})
);
emit RequestedRaffleWinner(requestId);
}
function fulfillRandomWords(
uint256 /** requestId */,
uint256[] calldata randomWords
) internal override {
uint256 indexOfWinner = randomWords[0] % s_players.length;
address payable recentWinner = s_players[indexOfWinner];
s_recentWinner = recentWinner;
s_raffleState = RaffleState.OPEN;
s_players = new address payable[](0);
s_lastTimeStamp = block.timestamp;
(bool success, ) = recentWinner.call{value: address(this).balance}("");
if (!success) {
revert Raffle__TransferFailed();
}
}
function getEntranceFee() public view returns (uint256) {
return i_entranceFee;
}
function getPlayer(uint256 index) public view returns (address) {
return s_players[index];
}
function getRecentWinner() public view returns (address) {
return s_recentWinner;
}
function getRaffleState() public view returns (RaffleState) {
return s_raffleState;
}
function getNumWords() public pure returns (uint256) {
return NUM_WORDS;
}
function getNumberOfPlayers() public view returns (uint256) {
return s_players.length;
}
function getLastestTimeStamp() public view returns (uint256) {
return s_lastTimeStamp;
}
function getRequestConfirmations() public pure returns (uint256) {
return REQUEST_CONFIRMATIONS;
}
function getInterval() public view returns (uint256) {
return i_interval;
}
function getSubscriptionId() public view returns (uint256) {
return i_subscriptionId;
}
}
You can use v2.5 like the above |
Beta Was this translation helpful? Give feedback.
You can create a subscription V2 from the contract (in Sepolia):
0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625