Low-level Requests

The straight way to fetch randomness from the Witnet oracle is by posting a low-level randomness data request to the WitnetRequestBoard.

However, you will then need to add logic within your smart contract as to await for an answer from the Witnet side-chain and handle corner-case revert situations at the Witnet level, before feeding your favourite Pseudo Random Number Generator (PRNG) algorithm with the 32-byte random seed provided by the Witnet oracle.

Besides, you or your contract will have to pay the required fee every time a randomness request is posted to the WitnetRequestBoard.

Best practices

Now, depending on the lifespan of your smart contract, you can actually compose your randomness data request following two different approaches:

1. First, if your contract needs a source of randomness for just once in its lifetime, you may just hardcode the Witnet data request bytecode with a predefined set of witnessing parameters, as shown in this code example.

The witnessing parameters of a Witnet data request determine aspects like how many Witnet nodes are required to participate in solving that data request, how much these nodes are incentivized if they are proven to behave honestly, and how much they will be pf

2. As a second approach, if you expect to repeatedly request for randomness an undetermined number of times, you may opt for using a pre-deployed copy of the WitnetRequestRandomness contract that will enable you, or your smart contract, to eventually change the witnessing parameters of your request.

There is no need to clone a randomness request contract before posting for new randomnness. Just once is required, and only in case you need to gain ownership of the request contract.

Security concerns

The RAD bytecode, accesible via the template() method, will always remain immutable, though.

Last updated

Was this helpful?