Last active
December 20, 2021 15:35
-
-
Save aesedepece/a60449aaf6e7c6d65b7e717966061a17 to your computer and use it in GitHub Desktop.
Witnet basic random bytes 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 { | |
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