Skip to content

Instantly share code, notes, and snippets.

@timosarkar
Created September 17, 2025 18:37
Show Gist options
  • Select an option

  • Save timosarkar/303d7f93821a35c77f4ddf1d6bd9d367 to your computer and use it in GitHub Desktop.

Select an option

Save timosarkar/303d7f93821a35c77f4ddf1d6bd9d367 to your computer and use it in GitHub Desktop.
Chainlink VRF
import "https://github.com/smartcontractkit/chainlink/blob/develop/contracts/src/v0.8/VRFConsumerBase.sol";
contract Test is VRFConsumerBase {
bytes32 public keyHash;
uint256 public fee;
uint256 public ticketPrice;
uint256 public result;
// ---------------- GOERLI ADDRESSESS----------------
// link address 0x326C977E6efc84E512bB9C30f76E30c160eD06FB
// key hash 0x0476f9a745b61ea5c0ab224d3a6e4c99f0b02fce4da01143a4f70aa80ae76e8a
//ChainlinkVRFCoordinator 0x2bce784e69d2Ff36c71edcB9F88358dB0DfB55b4
constructor(
address _ChainlinkVRFCoordinator,
address _ChainlinkLINKToken,
bytes32 _ChainlinkKeyHash,
uint256 _ticketPrice
) VRFConsumerBase(_ChainlinkVRFCoordinator, _ChainlinkLINKToken) {
keyHash = _ChainlinkKeyHash;
fee = 0.1 * 10 ** 18;
ticketPrice = _ticketPrice;
}
function getRandomNumber() public payable returns (bytes32 requestId) {
require(
LINK.balanceOf(address(this)) >= fee,
"YOU HAVE TO SEND LINK TOKEN TO THIS CONTRACT"
);
return requestRandomness(keyHash, fee);
}
// this is callback, it will be called by the vrf coordinator
function fulfillRandomness(
bytes32 requestId,
uint256 randomness
) internal override {
result = randomness;
}
receive() external payable {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment