Lottery Smart Contract
Let's delve into the intricacies of our Lottery Smart Contract.
1. Transparency & Verification: First and foremost, given the sensitivity and the demand for transparency associated with this contract, we've released it as "Contract Source Code Verified". This term, particularly common on platforms such as Etherscan or BscScan, means:
The source code of the smart contract has been made publicly accessible.
This source code has been audited and matches the bytecode stored on the blockchain.
The very essence of showing the "Contract Source Code Verified" tag is to:
a. Make the contract's source code available for public viewing. b. Ensure that this source code aligns seamlessly with the bytecode saved in the blockchain.
This process equips users with the capability to inspect the smart contract's source code, ensuring no hidden or malicious code, thereby fostering increased transparency and trust within the blockchain community.
2. Lottery Mechanics: Many users ponder over how the lottery chances are recorded, how random numbers for selecting winners originate, and how rewards are distributed. Here's the mechanism:
When an individual either purchases or upgrades an NFT, 5% of the payment, coupled with the designated chances for that tier, gets logged into the Lottery contract. For an in-depth technical breakdown, refer to the developer section.
Upon transferring the amount to this contract, denominated in 5sky tokens, no individual or group, regardless of their access level, can directly withdraw. Only after a 25-day cycle from the last draw will the tokens in the contract be disbursed amongst the winners.
Key Points:
Every participant retains their lottery chances indefinitely, even if they win multiple times. Their chances define a numeric range, and the lottery always takes place across all such ranges.
Initiating the lottery draw is open to all, without restrictions.
The contract owner lacks any authority to modify the chances count, be it an increment, decrement, or alteration.
3. Random Number Generation: For the pivotal aspect of random number generation, we've harnessed the VRF function hosted on the Chainlink oracle network. This ensures unbiased, verifiable, and truly random numbers for our lottery system.
Let's explore the advanced functionality of "Verifiable Random Function" or VRF within the blockchain context, especially as implemented by Chainlink.
Chainlink's VRF Explained:
Chainlink's VRF is designed specifically for applications requiring genuine, unpredictable, and verifiable random numbers, such as lotteries or gambling games.
Key Features of Chainlink VRF:
Unpredictability: The generated random number cannot be predicted before its creation.
Genuineness & Tamper Resistance: No participating party can manipulate or alter the result.
Verifiability: Every user can validate the proper and fair generation of the random number.
How Chainlink's VRF Works:
A smart contract pays Chainlink's VRF to request a random number.
An external VRF oracle, operating with a securely encrypted private key, produces a random number.
This oracle then constructs a proof validating that the random number was correctly generated and encrypted using the secure private key.
Both the generated random number and its corresponding proof are returned to the smart contract.
The smart contract, leveraging the oracle's public key, then examines the proof. If the proof is validated, the random number becomes usable.
Chainlink's VRF ensures the generation of random numbers on the blockchain is secure, transparent, and verifiable.
To bolster confidence in this system, you're encouraged to review the source code of the contract. Additionally, our contract's integration with Chainlink can be observed at: https://vrf.chain.link/bsc/932.
Lottery Process Explained:
Requesting Random Numbers: Initially, by invoking the
requestRandomNumbers
function, you will receive three random numbers via the Chainlink oracle. Note that this function can only be called after 25 days have passed since the last lottery.Determining Winning NFTs: Subsequently, using the obtained numbers and a specific formula through the
getRandomNumber
function, the winning NFT numbers will be determined based on a range of numbers in which the NFT numbers are registered.Prize Distribution: The tokens available in the contract are distributed among the winners based on this pattern:
First-place NFT: 55%.
Second-place NFT: 25%.
Third-place NFT: 15%.
Additionally, 5% of the tokens are transferred to the "charity" wallet to aid charitable causes. It's important to mention that all transactions of this wallet are made transparent through the website and social networks. Every charitable contribution is announced in full detail.
Any NFT has the chance to win in all three levels simultaneously even in one lottery, but it should have multiple chances for this to happen.
Invoking functions of this contract is possible for everyone, provided a certain number of days have passed since the last lottery.
Post-Lottery Process: After conducting the lottery, the lottery time is registered in the contract, and the date for the next lottery is set for 25 days later.
Adding Chances to NFTs: The process of adding chances to NFTs is through the "core" contract. This happens upon invoking functions like purchase or upgrade. You can track this in the logs recorded in our contracts or refer to the "developer" section for more technical details.
Prize Transfer: The prize is transferred to the last owner of the NFT at the time of the lottery.
Last updated