Page cover

πŸ’ͺTechnicals

circle-check

Let's first break down how the monthly draw will happen from a technical perspective. Starting with the fact it will be facilitated with the following 2 items:

  • Local Program (JavaScript)

  • Lucky Claw Smart Contract (Solidity)

Each month a lucky winner will be drawn using these two programs which will communicate with each other, here is the basic workflow / process:

In addition to helping automate / streamline the drawing process (by interacting with the smart contract, selecting / opening the winning animation / navigating to the winning NFT), the local program will be used to inject a random number into the smart contract. Before we jump into why this is important, we first need to understand an attribute of the Ethereum Virtual Machine.

circle-info

The Ethereum Virtual Machine (EVM) is deterministic system.

In mathematics, computer science and physics, a deterministic system is a system in which no randomness is involved in the development of future states of the system. A deterministic model will thus always produce the same output from a given starting condition or initial state.

This means, creating a truly random number, on-chain, is actually impossible. Instead we have to settle for a pseudo-random number, created by combining a number of network variables such as block height and gas limit. This will be made truly random by inputting an off-chain variable as a parameter. As the Flare Network creates blocks every 1-2 seconds and the fact that the gas height changes frequently (depending on the demand of the network), these two variables are a great starting point for randomness.

In order to achieve true randomness we need to bring data off-chain, into the smart contract.

The numbers (in a basic sense) are used to generate a very large number, subsequently the modulo operator (%) is used to output a minimum and maximum range (which will be 1 and the amount of NFTs minted).

The code snippet above comes from the publicly available smart contract deployed on the Flare Network, you can find it herearrow-up-right.

Last updated