chainlink icon indicating copy to clipboard operation
chainlink copied to clipboard

[SMRT] SubscriptionId in VRF and Automations

Open ArshilHapani opened this issue 9 months ago • 5 comments

In VRF and Automations contract there is one parameter subscriptionId in requestRandomWords of VRFCoordinatorV2Interface interface and addConsumer function from VRFCoordinatorV2Mock interface. The issue is that the type of subscriptionId is uint64 but the id provided by chainlink site is way to big e.g. 15356376269897563744780985323350096414521302577903754215356556594835422566595 Something like this which leads to error

   TypeError: value out-of-bounds (argument="_subId", value="15366376269897563744780985323350096414521302377970374217356556294839422166091", code=INVALID_ARGUMENT, version=6.12.0)
      at makeError (node_modules/ethers/src.ts/utils/errors.ts:687:21)
      at assert (node_modules/ethers/src.ts/utils/errors.ts:715:25)
      at assertArgument (node_modules/ethers/src.ts/utils/errors.ts:727:5)
      at NumberCoder._throwError (node_modules/ethers/src.ts/abi/coders/abstract-coder.ts:350:23)
      at NumberCoder.encode (node_modules/ethers/src.ts/abi/coders/number.ts:47:18)
      at /home/arshli-hapani/arshil/Future Span/Practice Span/web3/hardhat_smart_contract_lottery/hardhat_lottery_contracts/node_modules/ethers/src.ts/abi/coders/array.ts:64:19
      at Array.forEach (<anonymous>)
      at pack (node_modules/ethers/src.ts/abi/coders/array.ts:47:12)
      at TupleCoder.encode (node_modules/ethers/src.ts/abi/coders/tuple.ts:62:20)
      at AbiCoder.encode (node_modules/ethers/src.ts/abi/abi-coder.ts:195:15)

Version

{
  "devDependencies": {
    "@chainlink/contracts": "^1.1.0",
    "@nomicfoundation/hardhat-toolbox": "^5.0.0"
  }
}

ArshilHapani avatar May 04 '24 06:05 ArshilHapani

Hello, i'm having this issue too! :) The subId key provided by ChainLink is way too long, as explained by @ArshilHapani Example here

Varadiell avatar May 13 '24 00:05 Varadiell

As far as I understand, you can now only get a subscription ID for VRF v2.5. There is a guide on how to migrate from v2: https://docs.chain.link/vrf/v2-5/migration-from-v2#overview

But there is no mock interface for v2.5 (or I couldn’t find it). So now you have two options:

  1. for the real interface and testnet/mainnet use v2.5 with your subscription ID, and for the local chain use v2 code and a random subscription ID in uint64.
  2. or write your own mock for v2.5.

I think option 1 is easier.

psyfluid avatar May 13 '24 06:05 psyfluid

Hi again, I just got an advice from someone, and I managed to create a version 2.0 subscription that has a usable subId with this contract here! Once you use the "createSubscription", you can check here that your v2.0 subscription has been created.

Varadiell avatar May 13 '24 10:05 Varadiell

Chainlink documentation is now updated and they have included a example which works with v2.5 and subId of uint256.
https://docs.chain.link/vrf/v2-5/subscription/get-a-random-number

AayushOjha avatar Jun 02 '24 09:06 AayushOjha

@AayushOjha thanks for sharing this. found this really helpful

Patrick-Ehimen avatar Jul 23 '24 21:07 Patrick-Ehimen