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.