0

I've been following the documentation on docs.chain.link: https://docs.chain.link/docs/vrf/v2/examples/programmatic-subscription/ in order to have a programmatic way to handle a subscription. To fund the subscription the documentation says to write this kind of function:

function fundSubscription(uint256 amount) external onlyOwner {

    linkToken.transferAndCall(address(coordinator), amount, abi.encode(s_subscriptionId));
}

I modified this function a little bit and it looks like this:

function fundSubscription() public {

    linkToken.transferAndCall(address(coordinator), linkToken.balanceOf(address(this)), abi.encode(s_subscriptionId));
}

Instead of external onlyOwner it is just public, so that anyone can fund the subscription and instead of passing an amount, I just want to transfer the whole contract's balance to the subscription. Obviously before calling fundSubscription() I transferred to the contract a good amount of LINK token, so that is not the problem. The transaction reverts with a VirtualMachineError but nothing else is specified, so I can't tell what kind of error is this.

Error outputs:

VirtualMachineError(ValueError({'message': 'VM Exception while processing transaction: revert', 'stack': 'RuntimeError...c1c9b07ca57de0db5e968f553df052747dfdccf9d5bb6c5637348d', 'reason': None, 'error': 'revert', 'program_counter': 736}}}))

...........local\pipx\venvs\eth-brownie\lib\site-packages\brownie\network\transaction.py:446: VirtualMachineError

I'm on a development chain (I'm using brownie with ganache-cli).

Thank you in advance for your help.

3
  • Davide, what are the values for coordinator and linkToken? These are usually Chainlink Smart Contracts on the relevant testnet -- dont think they'd be available on your local testnet? For example the subscription account etc would not be available locally. While technically possible, I dont think it's feasible/usefuly for you to run the entire subscription management infrastructure locally on your dev machine. See for info on subscriptions: docs.chain.link/docs/vrf/v2/introduction/#subscriptions
    – ZeusLawyer
    Sep 21, 2022 at 3:51
  • Zeus I'm sorry, I solved the problem already a few days ago but for some reason, StackExchange didn't let me post the answer. I posted it now. Thanks for your help though! Sep 22, 2022 at 8:47
  • Well done! great to hear :)
    – ZeusLawyer
    Sep 23, 2022 at 1:32

1 Answer 1

0

I solved the problem by calling fundSubscription() function inside the VRFCoordinatorV2Mock instead of the fundSubscription() function inside my "own" contract.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.