Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warraich #24

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
704d993
Initial Commit:Multi-Signature Wallet
OmarMWarraich Nov 13, 2021
a6a0bd5
Deleted Changes
OmarMWarraich Nov 13, 2021
9b640be
Multi-Signature wallet-remix
OmarMWarraich Nov 13, 2021
07d5ef3
Defi Yield Aggregator with Solidity & JavaScript
OmarMWarraich Nov 13, 2021
9426d1e
Intro to Ethereum Digital Signatures
OmarMWarraich Nov 13, 2021
fe09f25
dapptools_simpleStorage
OmarMWarraich Nov 13, 2021
080e425
Removed dapp tools
OmarMWarraich Nov 13, 2021
b938a56
Initial Commit:Dapp tools installation
OmarMWarraich Nov 13, 2021
227815a
dapp init:Initialize new dapp
OmarMWarraich Nov 13, 2021
4328b7e
Removed Dapp
OmarMWarraich Nov 13, 2021
2167cae
dapp init: initialiaze dapp
OmarMWarraich Nov 13, 2021
7f8ddcf
Add Readme and modified 2
OmarMWarraich Nov 13, 2021
8f77056
Create your own flash mintable token
OmarMWarraich Nov 13, 2021
81179e8
Introduction to ethereum push notifications
OmarMWarraich Nov 13, 2021
6ea12d1
Make a raffle lottery dapp using chainlink random no.
OmarMWarraich Nov 14, 2021
f5f2a57
Find and open events in etherscan through web3
OmarMWarraich Nov 14, 2021
d92e8a5
Intro to Layer 2 Scaling with Optimism
OmarMWarraich Nov 15, 2021
0bcdd50
Optimistic Rollups with Optimism and Hardhat
OmarMWarraich Nov 15, 2021
a1684ee
Layer2 scaling with arbitrum
OmarMWarraich Nov 15, 2021
eb084a8
Intro to EIP1559 coding- gas burn
OmarMWarraich Nov 15, 2021
3a5c261
Intro to Blockchain Dev with Polygon
OmarMWarraich Nov 15, 2021
7465141
Launch your Blockchain App on Polygon
OmarMWarraich Nov 15, 2021
74ab95b
Fullstack app interacting with Aave lending protocol
OmarMWarraich Nov 15, 2021
fae52bf
Mint dai via backend
OmarMWarraich Nov 15, 2021
de07bbb
Create arbitrage trading with flash loans
OmarMWarraich Nov 15, 2021
bfcfeb5
React dApp template with Hooks&Redux&Web3
OmarMWarraich Nov 15, 2021
71ea2a9
defi saving app and testing defi on forked mainnet with money legos
OmarMWarraich Nov 15, 2021
5343c90
Deploy nft on binance smart chain
OmarMWarraich Nov 15, 2021
65141d2
Advanced dapp dev with web3-reactjs
OmarMWarraich Nov 15, 2021
c508340
An example of token swap using uniswapV2
OmarMWarraich Nov 15, 2021
797e0ac
Resources for Yearn Finance Strategy Development
OmarMWarraich Nov 15, 2021
ecbafed
Launching an ico in 2021
OmarMWarraich Nov 15, 2021
57c0099
Streaming payments with sablier-finance
OmarMWarraich Nov 15, 2021
9c14128
WalletConnect js example and some reorganization
OmarMWarraich Nov 15, 2021
4a7f5b5
Deploy a fullstack dapp on ipfs/fleek
OmarMWarraich Nov 15, 2021
36a8293
Create realtime defi analytics dashboard
OmarMWarraich Nov 16, 2021
a7f03a2
Passive Income with Flash Loans and some reorganization
OmarMWarraich Nov 16, 2021
1edce92
reorganize
OmarMWarraich Nov 16, 2021
d2b658a
arbitrage price swap and reorganized code
OmarMWarraich Nov 17, 2021
0307e6b
reorganized code and intro to ethers.js
OmarMWarraich Nov 17, 2021
7125929
Removed ethers.js
OmarMWarraich Nov 17, 2021
f998ec3
reorganized code
OmarMWarraich Nov 17, 2021
80d88d7
supply chain tutorial
OmarMWarraich Nov 17, 2021
f530abf
intro to dydx and furucmb and reorganized directories
OmarMWarraich Nov 17, 2021
2183fc1
flash-loan-tutorial side by side
OmarMWarraich Nov 17, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-2", "stage-3"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PRIVATE_KEYS=a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0
INFURA_ID=99999999999999999999999999999999
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.env
.env.local
build/
node_modules/
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
### About

Dapp University Simple Blockchain Raffle Ticket Lottery Decentralized Application to run raffles that makes
use of Verifiable Random Function (VRF) from Chainlink for reliable fair random numbers. A single ticket is chosen as the
winner and receives all the funds in the pool at the end of the raffle/lottery.

Anyone who has been a particiapant in lottery can be able to complete the raffle for a fee, so winner can be paid and raffle resets to allo new one to start play; this avoids the need to have an admin which can be a central point of failure, control, abuse, censorship, manipulation etc. Deployer can earn a percentage fee from the dapp as long as it runs.Blockchain Lotteries ensure fairness, transparency, censorship resistance and more.

Project is for learning and exploration purposes so better UI, and or logic can be created or extended.

[Read more about getting random number from Chainlink here](https://docs.chain.link/docs/get-a-random-number/)

### Technology Stack and Tools

* [Node Version Manager](https://heynode.com/tutorial/install-nodejs-locally-nvm) - node version manager
* [Metamask Wallet](https://metamask.io/) - Metamask Wallet
* [Chainlink](https://chain.link/)- Chainlink Oracles
* [VRF](https://docs.chain.link/docs/chainlink-vrf/) - Verifiable Random Function from Chainlink
* [Truffle](https://www.trufflesuite.com/) - development framework
* [React](https://reactjs.org/) - front end framework
* [Solidity](https://docs.soliditylang.org/en/v0.7.4/) - ethereum smart contract language
* [Ganache](https://www.trufflesuite.com/ganache) - local blockchain development
* [Web3](https://web3js.readthedocs.io/en/v1.3.0/) - library interact with ethereum nodes
* [JavaScript](https://www.javascript.com/) - logic front end and testing smart contracts
* [Infura](https://infura.io/) - connection to ethereum networks
* [Open Zeppelin](https://infura.io/) - smart contract libraries

##### Folder / Directory Structure (key folders)
* raffle_lottery_dapp
* migrations
* node_modules
* public
* src
* abis
* components
* contracts
index.js
* test

### Machine set up (Optional if you have not setup before or having challenges on your system)

1. Mac & Linux

- Have python 2.7 installed
Check if installed using command below
```sh
python -V
```
If not installed download from python [Python Download](https://www.python.org/downloads/) version 2.7 related to your system

- Download Ganache Graphical User Interface (GUI ) from [Truffle Framework Site](https://www.trufflesuite.com/ganache) choose related to your system

- Have node-gyp installed
Check if installed using command below
```sh

```
If not installed, install using command below
```sh
npm i -g node-gyp
```

2. Windows machine

Ignore Step 7 in the document below (document for bootcamp setup but applies to setup ubuntu environment)

- You may need to [Follow the Windows setup steps in this document](https://www.evernote.com/shard/s584/client/snv?noteGuid=960efc37-4e96-f95a-8c19-cc3b39b54836&noteKey=fd3fd7c99f629eb72a29552f16e4c9e8&sn=https%3A%2F%2Fwww.evernote.com%2Fshard%2Fs584%2Fsh%2F960efc37-4e96-f95a-8c19-cc3b39b54836%2Ffd3fd7c99f629eb72a29552f16e4c9e8&title=B00tc%2540mp%2Bwin10%2Benv.)

### Machine set up (Optional if you have not setup before or having challenges on your system)

1. Mac & Linux

- Have python 2.7 installed
Check if installed using command below
```sh
python -V
```
If not installed download from python [Python Download](https://www.python.org/downloads/) version 2.7 related to your system

- Download Ganache Graphical User Interface (GUI ) from [Truffle Framework Site](https://www.trufflesuite.com/ganache) choose related to your system

- Have node-gyp installed
Check if installed using command below
```sh

```
If not installed, install using command below
```sh
npm i -g node-gyp
```

2. Windows machine

Ignore Step 7 in the document below (document for bootcamp setup but applies to setup ubuntu environment)

- You may need to [Follow the Windows setup steps in this document](https://www.evernote.com/shard/s584/client/snv?noteGuid=960efc37-4e96-f95a-8c19-cc3b39b54836&noteKey=fd3fd7c99f629eb72a29552f16e4c9e8&sn=https%3A%2F%2Fwww.evernote.com%2Fshard%2Fs584%2Fsh%2F960efc37-4e96-f95a-8c19-cc3b39b54836%2Ffd3fd7c99f629eb72a29552f16e4c9e8&title=B00tc%2540mp%2Bwin10%2Benv.)

### Preconfiguration, Installation and Running project locally

1. You will need nvm if not laready installed; so you can use specific version node version 14 and above
```sh
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
$ source ~/.nvm/nvm.sh
```
Restart your terminal

2. Install node v14.16.0 or versions above
```sh
$ nvm install 14.16.0
$ nvm alias default 14.16.0
$ nvm use default
```

3. Install truffle globally if not installed.
Check if installed using
```sh
truffle version
```
If not installed install with below
```sh
$ npm install -g truffle
```

4. Ignore if either installed already! To fork need to use use ganache-cli vs [Ganache GUI](https://www.trufflesuite.com/ganache), install ganache-cli globally. Note that ganache-cli rus on port 8545 and ganache-gui runs on port 7545 as placced in truffle-config.js.
Check if ganache-cli installed first with
```sh
ganache-cli --version
```
If not installed install with below
```sh
$ npm install -g ganache-cli
```
Run ganache-cli fork of the ethereum mainnet in different terminal and keep running when compiling,testing, migrating, running app etc. Replace account with account with a lot of ETH and LINK e.g 0xbe6977e08d4479c0a6777539ae0e8fa27be4e9d6 [See here](https://etherscan.io/token/0x514910771af9ca656af840dff83e8264ecf986ca#balances)
```sh
ganache-cli -f https://mainnet.infura.io/v3/968a6207d32c4262ae008b7b55d0255e --unlock <account>
```

6. Install yarn if not installed. Check if installed using
```sh
yarn --version
```
If not installed install with below
```sh
$ npm install --global yarn
```
Add packages
```sh
yarn install
```

7. Duplicate the .env.example file and rename it .env. Populate your environment variables .env see .env.example
with your infura Id and your privateKey from Metamask account to do deployment e.g first account.

### Migrating contracts and Testing Locally to Local Ethereum using Ganache

1. Compile,test, Local Ganache Mainnet Fork
Ensure ganache is running in seperate terminal.
- If using Ganache CLI
```sh
$ truffle compile
$ truffle test --network development
```
Testing of front_end app will be done on Kovan network

### Migrating contracts Ethereum Kovan Network
Get Kovan ETH into a Metamask account from this [Kovan faucet click here](https://linkfaucet.protofire.io/kovan) or [Other Kovan Faucet Click Here](https://ethdrop.dev/). Copy your Metamask address into site and click "Send Me 0.1 Test ETH"

- Migrate
```sh
truffle migrate --network kovan
```
You can verify deployment, check transactions etc on [https://kovan.etherscan.io/](https://kovan.etherscan.io/)
copy the contract address and got to [Chainlink Kovan Faucet](https://linkfaucet.protofire.io/kovan) Enter the contract
address and request Test Link and Kovan ETH for account. [Read more here from Chainlink about how to fund your contract](https://docs.chain.link/docs/fund-your-contract/)

- Run app locally
Remember to have added LINK from above Faucet into deployed contract address
Remember to copy contract address and get some LINK for fees into it from faucet above.
Remember to get some Kovan ETH into a few addresses e.g 3-5 to act as users on the dapp from [Chainlink Kovan Faucet](https://linkfaucet.protofire.io/kovan)
```sh
yarn start
```
Connect Metamask to Kovan network

### Migrating contracts to Ethereum Mainnet Network
You need to have real value ETH in deploying account in Metamask.
- Migrate
```sh
truffle migrate --network mainnet
```
[View on Mainnet Scan here](https://etherscan.io/)

- Run app locally
```sh
yarn start
```

### Optional publish front end to Surge
1. Run build and enter build directory
```sh
$ yarn run build
$ cd build
```
2. Install surge globally:
```sh
$ npm i -g surge
```
"You may need to Login to surge and create account with email address and a password first time.
If you forgot password you can ask for reset on terminal and get password reset link in your email."
Select a unique domain name for your project e.g <uniquename>.surge.sh e.g asdfjkl.surge.sh where
my name of choice is asdfjkl

3. Deploy to surge.
```sh
$ surge --domain asdfjkl.surge.sh
```
...and follow the instructions

### Project enhancements and ideas

- UI/UX + leaner smart contract
- reduce number reloads or calls to blockchain and change only parts that need changing
- (who funds LINK with no admin, what is incentive) e.g any sender of LINK to contract when it runs out of LINK can earn fees
- more winners e.g person with most tickets in raffle gets a share of winnings etc
- assess for security and vulnerabilities
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const Migrations = artifacts.require("Migrations");

module.exports = function(deployer) {
deployer.deploy(Migrations);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
const RaffleLottery = artifacts.require("RaffleLottery");

module.exports = async (deployer) => {

let _VRF
let linkRef
let _linkToken
let _keyHash
let _feeLink
let _feePercent = 10 // 10%
let _ticketPrice = (0.001 *10 **18).toString()
let _totalTickets = 10
let linkDeposit = (100*10**18).toString()
const unlockedAccount = '0xbe6977e08d4479c0a6777539ae0e8fa27be4e9d6' // account with LINK and ETH

let miniABI = [
{
"constant": true,
"inputs": [
{
"name": "_owner",
"type": "address"
}
],
"name": "balanceOf",
"outputs": [
{
"name": "balance",
"type": "uint256"
}
],
"payable": false,
"type": "function"
},
{
"constant": false,
"inputs": [
{
"name": "_to",
"type": "address"
},
{
"name": "_value",
"type": "uint256"
}
],
"name": "transfer",
"outputs": [
{
"name": "success",
"type": "bool"
}
],
"payable": false,
"type": "function"
}
]

console.log(deployer.network)

if(deployer.network === 'kovan') {
console.log(`Deploying to KOVAN Network!!!!`)
_VRF = '0xdD3782915140c8f3b190B5D67eAc6dc5760C46E9'
_linkToken = '0xa36085F69e2889c224210F603D836748e7dC0088'
_keyHash = '0x6c3699283bda56ad74f6b855546325b68d482e983852a7a82979cc4807b641f4'
_feeLink = (0.1 * 10 ** 18).toString()
linkRef = new web3.eth.Contract(miniABI,_linkToken)
} else { // fork of mainnet or using mainnet itself
console.log(`Deploying to Mainnet or Mainet Fork Network!!!!`)
_VRF = '0xf0d54349aDdcf704F77AE15b96510dEA15cb7952'
_linkToken = '0x514910771AF9Ca656af840dff83E8264EcF986CA'
_keyHash = '0xaa77729d3466ca35ae8d28b3bbac7cc36a5031efdc430821c02bc31a238af445'
_feeLink = (2 * 10 ** 18).toString()
linkRef = new web3.eth.Contract(miniABI,_linkToken)
}

await deployer.deploy(
RaffleLottery,
_feePercent.toString(),
_ticketPrice,
_totalTickets.toString(),
_VRF,
_linkToken,
_keyHash,
_feeLink
)

// Save current deployed network
process.env.NETWORK = deployer.network

const raffleLottery = await RaffleLottery.deployed()

// Copy deployed contract address and deposit some LINK to pay for fees for VRF use
console.log(`DEPLOYED CONTRACT ADDRESS IS: ${raffleLottery.address}`)

if(deployer.network === 'development') {
// Transfer some LINK (e.g 100 LINK to contract)
await linkRef.methods.transfer(raffleLottery.address, linkDeposit).send({from: unlockedAccount})
const balanceLink = await linkRef.methods.balanceOf(raffleLottery.address).call()
console.log(`Balance LINK in contract is: ${balanceLink.toString()}`)
} // on Kovan network transfer some LINK into contract or get from a faucet

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "RaffleLotteryDapp",
"version": "0.1.0",
"description": "An Ethereum Marketplace",
"author": "Panacloud",
"dependencies": {
"@chainlink/contracts": "^0.2.1",
"@openzeppelin/contracts": "^4.1.0",
"@openzeppelin/test-helpers": "^0.5.12",
"@truffle/hdwallet-provider": "^1.4.1",
"babel-polyfill": "6.26.0",
"babel-preset-env": "1.7.0",
"babel-preset-es2015": "6.24.1",
"babel-preset-stage-2": "6.24.1",
"babel-preset-stage-3": "6.24.1",
"babel-register": "6.26.0",
"bootstrap": "4.3.1",
"chai": "4.2.0",
"chai-as-promised": "7.1.1",
"chai-bignumber": "3.0.0",
"dotenv": "^10.0.0",
"react": "16.8.4",
"react-bootstrap": "1.0.0-beta.5",
"react-dom": "16.8.4",
"react-scripts": "^2.1.8",
"truffle": "^5.3.6",
"web3": "^1.3.6"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
Binary file not shown.
Loading