Last active
December 21, 2021 09:28
-
-
Save aesedepece/5bfd2096c78d8f86f130fc8afcbb2fe5 to your computer and use it in GitHub Desktop.
Witnet basic RNG example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: MIT | |
pragma solidity >=0.7.0 <0.9.0; | |
import "witnet-solidity-bridge/contracts/interfaces/IWitnetRNG.sol"; | |
contract MyContract { | |
uint32 public randomness; | |
uint256 public latestRandomizingBlock; | |
IWitnetRNG witnet; | |
constructor () { | |
witnet = IWitnetRNG(address("<address of the WitnetRNG contract>")); | |
} | |
function getRandomNumber() external payable { | |
latestRandomizingBlock = block.number; | |
witnet.randomize(); | |
} | |
function fulfillRandomness() external { | |
assert(latestRandomizingBlock > 0); | |
randomness = witnet.random(type(uint32).max + 1, 0, latestRandomizingBlock); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment