I'm trying to use Chainlink's VRF to produce a random number. I've followed guides and produced a basic contract to do this, but getRandomNumber() isn't working. I am using the Sepolia test network.
//SPDX-License-Identifier: MIT
pragma solidity >=0.8.17;
import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";
contract Test is VRFConsumerBase {
uint256 public _randomSeed;
bytes32 internal keyHash;
/*
* https://docs.chain.link/vrf/v2/subscription/supported-networks
* Network: Sepolia
* LINK: 0x779877A7B0D9E8603169DdbD7836e478b4624789
* VRF: 0x8103B0A8A00be2DDC778e6e7eaa21791Cd364625
*/
constructor(address _vrfCoordinator, address _link)
VRFConsumerBase(_vrfCoordinator, _link) {
keyHash = 0x474e34a077df58807dbe9c96d3c009b23b3c6d0cce433e59bbf5b34f823bc56c;
}
function getRandomNumber()
public
returns (bytes32) {
uint256 _fee = 25 * (10 ** 16); // 0.25 LINK;
if (LINK.balanceOf(address(this)) < _fee) {
revert("Inadequate Link to fund this transaction");
}
return requestRandomness(keyHash, _fee);
}
function fulfillRandomness(bytes32 /*requestId*/, uint256 randomness)
internal
override {
_randomSeed = randomness;
}
function withdraw()
external {
bool success = LINK.transfer(msg.sender, LINK.balanceOf(address(this)));
if (!success) {
revert("withdrawLINK() PaymentFailure1");
}
}
}
When I try calling/transacting getRandomNumber() I get the following revert:
transact to Test.getRandomNumber errored: execution reverted
{
"originalError": {
"code": 3,
"data": "0x8129bbcd",
"message": "execution reverted"
}
}
The data of the error corresponds to "InvalidCalldata()". I believe the error is coming from: https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/VRFCoordinatorV2.sol (line 664)
However, I have no idea why this error is popping up. I followed instructions online creating this contract, but it doesn't work. If anyone could reproduce this and/or even fix and point out my error, I'd greatly appreciate it. Thank you.