The Randomness Pallet¶
Introduction¶
Moonbeam utilizes verifiable random functions (VRF) to generate randomness that can be verified on-chain. A VRF is a cryptographic function that takes some input and produces random values, along with a proof of authenticity that these random values were generated by the submitter. The proof can be verified by anyone to ensure the random values generated were calculated correctly. For more information on Moonbeam's on-chain randomness, such as an overview on the randomness sources, the request and fulfill cycle, and more, please refer to the Randomness on Moonbeam overview page.
The randomness pallet enables you to check on randomness requests that have not been fulfilled or purged, randomness results, and more. To actually request and fulfill randomness, you can use the randomness precompile and randomness consumer contracts. The precompile is a Solidity interface that enables you to request randomness, check on the status of requests, fulfill requests, and more through the Ethereum API. For more information on how to use both of these contracts, please refer to the Randomness Precompile guide.
This page will provide an overview of the storage methods and getters for the pallet constants available in the randomness pallet.
Randomness Pallet Interface¶
Storage Methods¶
The randomness pallet includes the following read-only storage methods to obtain chain state data:
- localVrfOutput() - returns the current local per-block VRF randomness
- palletVersion() - returns the current pallet version
- randomnessResults(PalletRandomnessRequestType) - snapshot of randomness to fulfill all requests that are for the same raw randomness
- relayEpoch() - returns the relay epoch
- requestCount() - returns the number of randomness requests made so far, and is used to generate the next request's uid
- requests(u64) - returns a given randomness request or all of the randomness requests that have not been fulfilled nor purged yet
Pallet Constants¶
The randomness pallet includes the following read-only functions to obtain pallet constants:
- blockExpirationDelay() - the number of blocks that must pass before a local VRF request expires and can be purged
- deposit() - the amount that should be taken as a security deposit when requesting random words. There is one deposit per request
- epochExpirationDelay() - the number of epochs that must pass before a BABE request expires and can be purged
- maxBlockDelay() - the maximum number of blocks (after the block in which the request was made) that can pass before a local VRF request is fulfilled
- maxRandomWords() - the maximum number of random words that can be requested
- minBlockDelay() - the minimum number of blocks (after the block in which the request was made) that must pass before a local VRF request can be fulfilled
| Created: August 12, 2022