The KEYS Metaverse Breakdown Edition 006 — How Chainlink VRF Supported KEYS Metaverse with Verifiable Randomness
On Apr 18, 2022, KEYS Metaverse ran a giveaway where 12 Meta Mansions holders were randomly selected to win a reward from a total prize pool of 444 ETH. In total, 11 people were selected to win 4 ETH each, and one person was selected to win 400 ETH. To help ensure a transparent selection process in our giveaway, we used Chainlink Verifiable Random Function (VRF) — the industry-standard RNG solution.
The KEYS team was challenged to design a fair, transparent, and effective solution for the selection process with deep thought and care about the specifics of the giveaway. After evaluating countless potential methods for sourcing verifiable randomness for our giveaway, we decided to choose the best random number generator (RNG) in the Web3 space, Chainlink VRF.
Chainlink VRF works by combining block data that is still unknown when the request is made with the oracle node’s pre-committed private key to generate both a random number and a cryptographic proof. The KEYS Metaverse smart contract will only accept the random number input if it has a valid cryptographic proof, and the cryptographic proof can only be generated if the VRF process is tamper-proof. This provides our users with automated and verifiable assurances directly on-chain that the winner selection process used verifiable randomness.
Let’s take a look at the code behind the smart contract facilitating our giveaway. Since the contract was one-time use, we decided to deploy it on the Rinkeby testnet to save gas costs. The code is located here:
As you can see from the link above, in the `requestRandomWords` function, we request a random number from the Chainlink VRF Coordinator contract. Subsequently, the random number received from Chainlink VRF is used as the seed for our randomizer when the `chooseWinner` function is called.
After `chooseWinner` is called, there is no way to update the `randomlyChosenNumber`. Then, we call the `winner` function with a given index to determine the selected winner for that index.
Here are the rules for which index corresponds to which winners:
- After chooseWinners() sources a random number from Chainlink VRF, that number becomes a seed.
- Each “winner” is determined using a hashed combination of that random number and an “index.”
- The largest winner will be index = 0. The next 11 winners will be index = 1, 2, 3, 4, …, 12.
- If any team members of KEYS Metaverse “win”, they’re disqualified, so we ignore them and draw an additional number.
- For example: If team member wins on index = 8, then the largest winner = 0, others = 1 2 3 4 5 6 7 9 10 11 12 13.
- For example: If a team member wins the largest prize, then the largest winner = 1, others = 2 3 4 5 6 7 8 9 10 11 12 13
- For example: If a team member wins 9 10 and 11, then the largest winner = 0, others = 1 2 3 4 5 6 7 8 12 13 14 15
- If a duplicate number is chosen, it’s also disqualified and we treat it the same way as if a team member would have been selected (a person can only win once).
- This returns a number between 0 and 4443.
- There are 4444 potential winning mansion ids, and we sort them in ascending order.
- The lowest potential winner number corresponds to 0.
- The highest number corresponds to 4443.
Finally, here’s the etherscan transaction of the transfer, so you can check it out yourself and our tweet commemorating the moment:
https://etherscan.io/tx/0xb271ebce8ea3885191c91a033e4d0ffe51a12d950cf60f3ff63e5a2fee2684c6
We hope you enjoyed taking a peek under the hood of how we conducted our giveaway with tamper-proof randomness supplied by Chainlink VRF. Be sure to jump into the KEYS Metaverse Discord Server where our community is sharing knowledge and helping each other learn about the exciting new technologies emerging every day.

About Chainlink
Chainlink is the industry standard for building, accessing, and selling oracle services needed to power hybrid smart contracts on any blockchain. Chainlink oracle networks provide smart contracts with a way to reliably connect to any external API and leverage secure off-chain computations for enabling feature-rich applications. Chainlink currently secures tens of billions of dollars across DeFi, insurance, gaming, and other major industries, and offers global enterprises and leading data providers a universal gateway to all blockchains.
Learn more about Chainlink by visiting chain.link or reading the developer documentation at docs.chain.link. To discuss an integration, reach out to an expert.
About KEYS Metaverse
KEYS Token is a startup powering real-estate and luxury-asset transactions on the blockchain, poised to revolutionize the way assets are exchanged in both the metaverse and the physical world. Their comprehensive product roadmap combines multiple elements of technology, including web3 and augmented reality, to converge the physical and digital realms in what will be, without any doubt, the next evolution of real estate, the internet, and social networks. www.keystoken.io | www.metamansionsbykeys.com