soliditysmartcontractschainlinkfoundry-code-repositories

Chainlink VRF: Created Subscription ID Mismatch Between On-Chain and Dashboard


I'm encountering an issue where the subscription ID returned by my script is different from the one shown on vrf.chain.link for the Sepolia network, which when i try to fund to the subid from my script will result InvalidSubscriptionId.

Testcreatesubscription.s.sol:

// SPDX-License-Identifier: MIT

pragma solidity  ^0.8.19;
import {Script} from "forge-std/Script.sol";
import {CodeConstants} from "script/HelperConfig.s.sol";
import {IVRFCoordinatorV2Plus} from "@chainlink/contracts/src/v0.8/vrf/dev/interfaces/IVRFCoordinatorV2Plus.sol";
import {console} from "forge-std/console.sol";

contract CreateSubscription is Script,CodeConstants{
    function run() public{
        createsubscription_onsepolia();
    }

    function createsubscription_onsepolia() public {
        if(block.chainid == ETH_SEPOLIA_CHAN_ID){
            vm.startBroadcast(0x57099326F00d72E00dc4416FF638136853E5330e);
            uint256 subid = IVRFCoordinatorV2Plus(0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B).createSubscription();
            vm.stopBroadcast();
            console.log("subid on sepolia: ",subid);
        }
    }
}

when i run forge script script/Testcreatesubscription.s.sol:CreateSubscription --rpc-url $SEPOLIA_RPC_URL --account sepolia_testing_account --broadcast -vvvv

sepolia_testing_account is my metamask account, which I have stored in the keystore.

logs result:

== Logs == subid on sepolia: 1756636573672805867076888413.....

Setting up 1 EVM.

Simulated On-chain Traces:

[88720] VRFCoordinatorV2_5::createSubscription() ├─ emit SubscriptionCreated(subId: 175663657367280586707688841388762055..... [1.756e76], owner: 0x57099....) └─ ← [Return] 1756636573672805867076888413887... [1.756e76]

==========================

Chain 11155111

Estimated gas price: 0.724514652 gwei

Estimated total gas used for script: 151638

Estimated amount required: 0.000109863952799976 ETH

========================== Enter keystore password:⠂ Sequence #1 on sepolia

sepolia ✅ [Success] Hash: 0x93a569514837d5d7dd8f525e1fdf105b541fde506522cf9c6b7d0173779c0da7 Block: 8028451 Paid: 0.000043162465117744 ETH (109784 gas * 0.393158066 gwei)

✅ Sequence #1 on sepolia | Total Paid: 0.000043162465117744 ETH (109784 gas * avg 0.393158066 gwei)

Even though the script logs show that my subscription ID is 175663657367280586707688841388762055..., when I check vrf.chain.link on the Sepolia network, I see a completely different subscription ID: 426994294831235659204431318963817900788974.....

I've been struggling with this for hours, and even ChatGPT couldn't figure it out. Does anyone know what I might be doing wrong? Any help would be greatly appreciated!


Solution

  • The subscription ID returned by IVRFCoordinatorV2Plus(0x9DdfaCa8183c41ad55329BdeeD9F6A8d53168B1B).createSubscription(); when executing the Foundry script is not necessarily the actual subscription ID created on the VRF Dashboard.

    This is because the returned value comes from a simulated execution before the transaction is confirmed on-chain. Foundry simulates the return value before the transaction is mined, which can result in a discrepancy between the simulated value and the actual on-chain value.

    Therefore, you must retrieve the actual value either from the transaction logs via a block explorer or directly from the VRF Dashboard.