Skip to content
Verified contractPartialMIT

luckyDraw

Address0xc70688b9779bc3196dcb258c95e7e641f0be18f4
Balance

0 ETH

 

Transactions

1

 

Compiler

solc 0.8.26

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.26+commit.8a97fa7a
Language
solidity
Optimization
No
EVM version
cancun
License
MIT
Match
Partialcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
20,855,287
Creation transaction
0xfe67d60cba…bdab1aa659

luckyDraw.sol

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;

contract luckyDraw {
    uint256 public totalCandidates = 117;

    function unveil_lucky() public view returns (uint8[] memory) {
        uint256 target = 20860406;
        require(
            block.number > target,
            "Result will be released at ~2024/9/30 10:10"
        );
        return draw(target);
    }

    function test_run() public view returns (uint8[] memory) {
        uint256 target = 20855330;
        require(
            block.number > target,
            "Result will be released at ~2024/9/29 17:15"
        );
        return draw(target);
    }

    // select at least 30% candidates
    function draw(uint256 h) public view returns (uint8[] memory) {
        require(block.number > h, "Block not ready");

        uint8[] memory luckyOnes = new uint8[](totalCandidates);
        bool[] memory picked = new bool[](totalCandidates);

        uint256 counter = 0;
        bytes32 seed = blockhash(h);
        while (true) {
            for (uint256 i = 0; i < 32; i++) {
                uint8 id = uint8(seed[i]);
                if (id >= totalCandidates) continue;
                if (!picked[id]) {
                    picked[id] = true;
                    luckyOnes[counter] = id + 1;
                    counter++;
                }

                if ((counter * 100) / totalCandidates > 30) return luckyOnes;
            }
            seed = keccak256(abi.encodePacked(seed));
        }

        return luckyOnes;
    }
}
Compiler settingsShow
{
  "metadata": {
    "bytecodeHash": "ipfs"
  },
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": false
  },
  "evmVersion": "cancun",
  "remappings": []
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.