Chainlink VRF V2 – Solving Callback fulfillRandomWords Issue

chainlinksolidityvrf

I have the following code that is deployed using REMIX Injected Web3 into AVALANCHE FUJI TESTNET

import '@chainlink/contracts/src/v0.8/interfaces/VRFCoordinatorV2Interface.sol';
import '@chainlink/contracts/src/v0.8/VRFConsumerBaseV2.sol';

contract ULotto is VRFConsumerBaseV2{

VRFCoordinatorV2Interface COORDINATOR;

    //values for CHAIN Link Integration
    uint64 s_subscriptionId; 
    address vrfCoordinator = 0x2eD832Ba664535e5886b75D64C46EB9a228C2610;
    bytes32 s_keyHash = 0x354d2f95da55398f44b7cff77da56283d9c6c829a4bdf1bbcaf2ad6a4d081f61;
    uint32 callbackGasLimit = 2000000;
    uint16 requestConfirmations = 3;
    uint32 numWords = 6;
    uint256[] public s_results;

constructor(uint64 subscriptionId) VRFConsumerBaseV2(vrfCoordinator){
        owner = msg.sender;
        lotteryIdCounter = 1;

        COORDINATOR = VRFCoordinatorV2Interface(vrfCoordinator);
        s_subscriptionId = subscriptionId;
    }

function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override {
        s_results = randomWords;
    }

    function drawNumbers() public onlyOwner returns (uint256 requestId){
        //dragons require logic here

        requestId = COORDINATOR.requestRandomWords(
            s_keyHash,
            s_subscriptionId,
            requestConfirmations, 
            callbackGasLimit,
            numWords
        );

    }

}

When I call draw numbers, I can see from testnet.snowtrace.io/ that the callback to my function has error.

enter image description here
enter image description here
Internal TXNs of supposed callback

Can someone point me in the right direction?

Best Answer

There are a few things to check with issues like this.

  1. Check that the Contract is a consumer in the VRF Subscription, as Richard Horrocks mentioned above
  2. Double check you supplied the correct subscription ID to the contract
  3. Try running the fulfillRandomWords function to see what the gas requirement is. Often the callbackGasLimit will need to be increased if the logic in the callback is involved.
Related Topic