Example - Draw a Lottery
The DrawLotteryExample
illustrates the utilization of GeneralRandcastConsumerBase
and RandcastSDK
to construct a straightforward lottery system.
The contract structure is similar to the previous example:
It first issues a random number request, setting the request type toRequestType.RandomWord
, and sets params
for the length of the returned array (the total number of lottery tickets). Upon receiving the tickets in the form of an array, in the _fulfillRandomWords
function, we call the RandcastSDK.draw
method to randomly pick a subset of elements based on their index positions in the array representing the winners.
If you want to draw a subset of elements from an existing array, consider requesting a single randomness by using _requestRandomness(RequestType.Randomness, params)
and then calling draw(randomness, indices, winnerNumber)
.
Last updated