$4.88 2.38%
LINK · 4w

How to Generate Truly Random Numbers in Solidity and Blockchain

Approach 3: Chainlink VRF

Let’s get into the good stuff.

An interesting StackExchange question was posted a few years ago: “How can I securely generate a random number in my smart contract?”, with the current top answer explaining what appears to be the best system.

A request for a random number is sent to multiple nodes, and each sends a provably random response (using a public key, private key, and seed). Each node has their response bitwise XOR’d together to generate the resulting random number.

You can read into the math of it later, but there are two main parts that are explained:

The random number is generated in a verifiably random fashion, using a public and private key to cryptographically prove that the number was random. This random number generation is done across multiple nodes to guarantee that there is no single source of failure, and then XOR’d (a way to combine the answers) to make the final result.

You’ll see these are common themes in blockchain, decentralization, and cryptography (cryptography might be slightly more obvious).

Building a blockchain application with centralized data sources and oracles is like buying a bike so you don’t have to walk to work anymore, then proceeding to continue to walk to work with your bike strapped to your back.

Original image from Chainlink Blog

These concepts are the backbone of the Chainlink VRF.

Right now, Chainlink has a working rendition of concept #1 live on testnet (cryptographically provable random numbers) and is in development of concept #2, the crescendo of provably random numbers, decentralization of provably random numbers. You can build a provably random application on Kovan, Ropsten, and Rinkeby right now.

Chainlink is currently “in the final stages of security review for Chainlink VRF and wants to engage with our users in both the developer community and the academic community”, so you can be one of the first applications to run a sm...

Continue on
Recent news