Skip to content

Instantly share code, notes, and snippets.

@aesedepece
Last active December 21, 2021 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aesedepece/5bfd2096c78d8f86f130fc8afcbb2fe5 to your computer and use it in GitHub Desktop.
Save aesedepece/5bfd2096c78d8f86f130fc8afcbb2fe5 to your computer and use it in GitHub Desktop.
Witnet basic RNG example
// 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