This project serves educational purposes, offering a web application that allows users to place bets on randomly generated numbers using Ether. A smart contract manages the bets, receives Ether, and determines the winning number randomly. The participant with the correct number receives the accumulated Ether sum.
The project is divided into 3 projects:
- Lottery Smart Contract*: This handle the bets and decided the winner of the bets. Also reward the winner with all money available;
- Back-end Lottery Smart Contract: This handle the requests from the user and send it to the smart contract.
- Front-end Lottery Smart Contract: This is the user interface that the use perform actions.
- Solidity: Solidity is the programming language for writing smart contracts on the Ethereum blockchain. Learn more about Solidity.
- Ganache: Ganache is employed to run the Ethereum blockchain locally. More details about Ganache can be found.
- Truffle: Truffle is the chosen framework for smart contract development.
- Initialize Truffle project:
npm install -g truffle
truffle init
-
Create a new Solidity file in the contracts folder.
-
Compile the Solidity program:
truffle compile
- Migrate the smart contract:
truffle migrate
- Access the Truffle console:
truffle console
- Unit testing of the contract
truffle test
Whether you followed the previous steps: 3, 4 and 5.
You are now at truffle console right, so type these commands:
- let lottery = await Lottery.deployed()
- lottery.contractName()
As output you should see the message: The Lottery Contract is OnLine