When I try to add a consumer to my VRF2 subscription via the Subscription Manager, the transaction completes successfully. This also works when interacting with the chainlink contract directly on etherscan.
I'd like to deploy a contract that automatically adds itself to my existing chainlink subscription upon deployment. I have used the code provided by chainlink here.
The following code works on deployment:
constructor() VRFConsumerBaseV2(vrfCoordinator) {
COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator);
LINKTOKEN = LinkTokenInterface(link_token_contract);
s_owner = msg.sender;
//Create a new subscription when you deploy the contract.
createNewSubscription();
}
function createNewSubscription() private onlyOwner {
s_subscriptionId = COORDINATOR.createSubscription();
COORDINATOR.addConsumer(s_subscriptionId, address(this));
}
As seen above the contract deploys and creates a new subscription and adds a consumer. I originally simply wanted to add a consumer to an existing subscription so I modified the createNewSubscription function.
// Create a new subscription when the contract is initially deployed.
function createNewSubscription() private onlyOwner {
s_subscriptionId = COORDINATOR.createSubscription();
COORDINATOR.addConsumer(1234, address(this));
}
This does not work. Of course I already have a subscription(1234) that works and can add to it manually, calling from another contract does not work. I have also tried assigning s_subscriptionId initially:
uint64 s_subscriptionId = 1234;
which also does not seem to be working.
Further tests with (,s_subscriptionId,,) = COORDINATOR.getSubscription();
also failed.
Pointers on how to debug this would also be welcome as I'm learning solidity.