Lottery

About The Project

This tutorial is a step-by-step guide to creating an automation for generating random words using Chainlink's VRF and Chainlink Automation features.

We will demonstrate how to build this project, showcasing the use of our SDK and Chainlink's resources. Follow each step carefully to generate your own automation for random words.

In this project, we will be using the following functionalities:

  • Price Feeds

  • VRF (Verifiable Random Function)

  • Automation

In this example, we'll cover the main part of creating VRF and Automation using our SDK.


DEMO

We've developed a sample project utilizing these features, and you can check out the complete implementation at:

Cryptum - Lottery

The project involves a lottery where the user places a bet by providing 10 numbers. If the newly generated word contains 6 or more of these specified numbers, the user receives a reward.

Explore this playground to simulate bets and observe Chainlink VRF's functionality generating random numbers every 100 mined blocks on the POLYGON - MUMBAI network.

Access the link:

Lottery Playground

Provide your email and start playing.

If the game is paused, you can click to initiate.


Requirements

  • Basic knowledge of JavaScript.

  • NPM

  • Node version: ^14.17.0

  • Create account Dashboard Cryptum

  • Faucets (testnet) LINK and MAUTIC

Faucets

Many developers and test users of Web3 applications are faced with a barrier: the lack of balance in their wallets to test. This is because for you to carry out any transaction on the blockchain, you need to pay fees for the network to mine (validate) your transaction.

To solve this, all blockchain protocols in Test environment (Testnet) provide websites for you to inform your wallet and receive balance to be able to use it.

  • MATIC - https://mumbaifaucet.com/

  • LINK - https://faucets.chain.link/mumbai

Getting Started

Open your project

Install using npm manager or yarn

step 1

With a valid Cryptum API Key, you can then instantiate the SDK as follows:

Implementation example in: cryptum-lottery/service/Cryptum.js

step 2

Then you call the generateWallet() function passing the protocol you want:

Implementation example in: cryptum-lottery/controller/Wallet.js

step 3

Add faucets to your new wallet.

MATIC and LINK as described in: Faucets

step 4

Create Subscription Chainlink VRF.

Implementation example in: cryptum-lottery/controller/Lottery.js

step 5

Add Funds with LINK in your Subscription.

step 6

Automation setup; this stage is where we create the process responsible for generating a new random word every 'N' blocks.

Implementation example in: cryptum-lottery/controller/Lottery.js

step 7

Add Funds with LINK in your Automation.

Perform a transfer of LINKs from your wallet to the contract address generated in step 6.

Implementation example in: cryptum-lottery/controller/Lottery.js

step 8

Register Upkeep.

At this stage, we will register our automation, initiating the process so that new random words are generated after every N number of blocks mined on the blockchain.

Implementation example in: cryptum-lottery/controller/Lottery.js

step 9

Getting the generated random words.

Get the last request ID generated in your subscription:

Implementation example in: cryptum-lottery/cron/index.js

step 10

Getting information about your subscription and automation:

List all upkeeps

Get info Upkeep ID:

Implementation example in: cryptum-lottery/controller/Lottery.js

You can also track your subscription and automation through the chainlink website.

VRF

Automation

Last updated