Giter Site home page Giter Site logo

ovr-platform / ovrland-monthly-chainlink-extractions Goto Github PK

View Code? Open in Web Editor NEW
3.0 4.0 0.0 19.23 MB

The 10% of the OVR tokens realized from OVRLand monthly sale is being distributed to lucky OVRLand owners who bought OVRLand during each month under consideration. Ten (10) lucky winners are being randomly selected using the Chainlink’s VRF every month. However, it is important to note that in every succeeding extraction we remove the OVRLands of the winner of the previous extraction so the person can’t win twice.

extractions

ovrland-monthly-chainlink-extractions's Introduction

OVRLand Monthly ChainLink Extraction

To view the results on Polygonscan click on "Read Contract" and scroll down to tab number 5 "Result" and enter the draw number.

Smart Contract Source Code

Randomness is very difficult to generate on blockchains. The reason for this is because every node must come to the same conclusion, forming a consensus. There's no way to generate random numbers natively in smart contracts, which is unfortunate because they can be very useful for a wide range of applications.

Chainlink VRF (Verifiable Random Function) is a provably-fair and verifiable source of randomness designed for smart contracts. Smart contract developers can use Chainlink VRF as a tamper-proof RNG to build reliable smart contracts for any applications which rely on unpredictable outcomes:

  • Blockchain games and NFTs
  • Random assignment of duties and resources (e.g. randomly assigning judges to cases)
  • Choosing a representative sample for consensus mechanisms

Chainlink VRF enables smart contracts to access randomness without compromising on security or usability. With every new request for randomness, Chainlink VRF generates a random number and cryptographic proof of how that number was determined. The proof is published and verified on-chain before it can be used by any consuming applications. This process ensures that the results cannot be tampered with nor manipulated by anyone, including oracle operators, miners, users and even smart contract developers.

Here how OVR uses Chainlink VRFConsumerBase Contract:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.7;

import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

contract RandomWinner is VRFConsumerBase, Ownable {
    bytes32 internal keyHash;
    uint256 internal fee;
    uint256 public id = 0;

    mapping(uint256 => uint256) public partecipants;
    mapping(uint256 => uint256) public draw;

    /**
     * Constructor inherits VRFConsumerBase
     *
     * Network: Polygon Mainnet
     * Chainlink VRF Coordinator address: 0x3d2341ADb2D31f1c5530cDC622016af293177AE0
     * LINK token address:                0xb0897686c545045aFc77CF20eC7A532E3120E0F1
     * Key Hash: 0xf86195cf7690c55907b2b611ebb7343a6f649bff128701cc542f0569e2c549da
     */
    constructor()
        VRFConsumerBase(
            0x3d2341ADb2D31f1c5530cDC622016af293177AE0, // VRF Coordinator
            0xb0897686c545045aFc77CF20eC7A532E3120E0F1 // LINK Token
        )
    {
        keyHash = 0xf86195cf7690c55907b2b611ebb7343a6f649bff128701cc542f0569e2c549da;
        fee = 0.0001 * 10**18; // 0.0001 LINK (Varies by network)
    }

    function setPartecipants(uint256 _partecipants) internal {
        partecipants[id] = _partecipants;
    }

    function results(uint256 _id)
        public
        view
        returns (uint256 _winner, uint256 _partecipants)
    {
        return (draw[_id], partecipants[_id]);
    }

    /**
     * Requests randomness
     */
    function getRandomNumber(uint256 _partecipants)
        public
        onlyOwner
        returns (bytes32 requested)
    {
        setPartecipants(_partecipants);
        require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK");
        return requestRandomness(keyHash, fee);
    }

    /**
     * Callback function used by VRF Coordinator
     */
    function fulfillRandomness(bytes32 requestId, uint256 randomness)
        internal
        override
    {
        draw[id] = (randomness % partecipants[id]) + 1;
        id++;
    }
}

ovrland-monthly-chainlink-extractions's People

Contributors

marcogianni avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.