Skip to content

Instantly share code, notes, and snippets.

@aesedepece
Last active December 20, 2021 15:35
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/a60449aaf6e7c6d65b7e717966061a17 to your computer and use it in GitHub Desktop.
Save aesedepece/a60449aaf6e7c6d65b7e717966061a17 to your computer and use it in GitHub Desktop.
Witnet basic random bytes example
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
import "witnet-solidity-bridge/contracts/interfaces/IWitnetRNG.sol";
contract MyContract {
bytes32 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.randomnessAfter(latestRandomizingBlock);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment