Skip to content

In order to ensure security and traceability, We decided to implement a lottery game in the blockcahin. At the end of the lottery, the owner can randomly pick a winner and transfer him all the funds; for the randomization we used chainlink's VRF direct funding method

License

Notifications You must be signed in to change notification settings

nour-karoui/Lottery-in-the-blockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HELLO This is LOTTERY IN THE BLOCKCHAIN

What is Lottery in the blockchain?

It is a decentralized app hosted on Goerli Testnet built with Brownie Framework and Web3.py Library.

  1. The contract owner starts the lottery
  2. Gamblers can enter Lottery with ETH based on USD
  3. The contract owner will choose when the lottery is over
  4. A winner is selected randomly, and he gets to win all the ether in the contract

Install Dependencies

In order to compile and deploy the contracts locally or on a testnet, you need to have Ganache and Metamask

Run this command to install dependencies:

    pip3 install eth-brownie python-dotenv pytest

For me, I had to install a virtual environment before installing dependencies; check out this link for more details

Compile Contracts

To compile the contracts, simply run this command:

    brownie compile

Deploy Contracts

Before deploying the contract, you first have to make sure to fill the .env file. Check .env.example

Locally

run this command:

    ganache-cli

and then in another terminal, run this command

    brownie run scripts/deploy_lottery.py

Here is the result of deploying the contract locally

image

Testnet

    brownie run scripts/deploy_lottery.py --network goerli

Deploying the contract on a Testnet takes more time than deploying it locally so be patient.

Here is the result of Deploying the contract on Goerli, you can verify it on etherscan

image

RemixIDE

Copy and paste the content of contracts/Lottery.sol in RemixIDE and play with it

Testing the Contract's Functionalities

To test the functionalities of our smart contract, you can first do that manually by going to scripts/deploy_lottery.py and uncomment the method calls, as shown in the screenshot below

image

and run the command

    brownie run scripts/deploy_lottery.py --network goerli

Limitations

Locally, end_lottery() and pick_winner() won't work because we are using contract deployed on the blockchain and for the VRFV2Wrapper there are no current mocks that we can use

Automated Testing

Unit Tests will only run on a development local blockchain with this command

    brownie test -s

Integration Tests will only run on a Testnet with this command

    brownie test -s --network goerli

About

In order to ensure security and traceability, We decided to implement a lottery game in the blockcahin. At the end of the lottery, the owner can randomly pick a winner and transfer him all the funds; for the randomization we used chainlink's VRF direct funding method

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published