This is my take on Ethereum Smart Contract Programming 201 assignment of creating a smart contract and dapp to bet on a coin flip.
This project also contains a (naive) oracle implemented in node to provide random numbers to the blockchain.
Install dependencies using yarn install
in the project's root. npm install
should work the same.
- Have Ganache up an running
- Run
yarn migrate --reset
to deploy the contract on the local Ganache network
- Install Metamask or enable Brave wallet
- In the wallet network selection use "Custom RPC" to add a new network,
name it "Ganache" and copy the RPC network address from Ganache interface
(usually
http://127.0.0.1:7545
) - In the wallet accounts, select "import account" and use one of the Ganache generated private address
- From Ganache get the private key of the account with index 3 (:warning: only use local, test only key that you can expose)
- From Ganache get the Oracle deployed contract address
- Run the oracle with
node oracle.js -a <private_key_index_3> -c <oracle_contract_address>
- The oracle should now be listening to the blockchain, use
ctrl-C
twice to quit
- Run
yarn dev
to start the dapp local server - Navigate to
http://localhost:8080/
and you should see the dapp
- Click the "Connect to Wallet" button at the top right, you should be presented with Metamask connection interface; accept the connection
- Add a sum to bet in the input field
- Click on "Place bet"