This repository contains a create-react-app template that can be used to develop an ethereum dApp.
-
Install Create-React-App package
$ npm install -g create-react-app
-
Create a project using this template
$ create-react-app project-name --template ethereum-fullstack
-
Switching to test network (RINKEBY) (Optional)
- Please skip this step if you want to use local network
- Change line -
const NETWORK = LOCAL_NETWORKtoconst NETWORK = TEST_NETWORKinhardhat.config.js - Replace
YOUR_ALCHEMY_API_KEYwith your api key from alchemy in.envfile - Replace
YOUR_WALLET_PRIVATE_KEYwith your wallet's private key from metamask wallet in.envfile
-
Running test for sample contract
npx hardhat test
-
Start your react frontend
npm start
-
Start a hardhat node
npx hardhat node
-
Connect hardhat node to Metamask
Open Metamask > Select the network dropdown from the top left > Select
Custom RPCand enter the following details:- Network Name:
<Enter a name for the network> - New RPC URL:
http://127.0.0.1:8545 - Chain ID:
31337
Click save. You can use this network to connect to the local hardhat node.
- Network Name:
-
Connect your local hardhat account to Metamask for making transactions
- After running
npx hardhat nodeyou will see a list of 20 addresses logged in the terminal - To configure an account copy its private key from the terminal (i.e the text after
Private Key:) - Open Metamask > Click the account icon on top right > Import Account > Paste the private key you just copied > click Import
- You should now have the account connected with 10000 ETH
- After running
Your environment will have following set up:
- A sample frontend: Sample application which uses Create React App along with its test.
- Hardhat: An Ethereum development task runner and testing network.
- Mocha: A JavaScript test runner.
- Chai: A JavaScript assertion library.
- ethers.js: A JavaScript library for interacting with Ethereum.
- Waffle: To have Ethereum-specific Chai assertions/mathers.
Error HH8: There's one or more errors in your config fileerror: If you get this error try setting up yourYOUR_ALCHEMY_API_KEYandYOUR_WALLET_PRIVATE_KEYin .env file