Getting Started with a simple decentralized application(DAPP) using react, solidity & local Ethereum network for testing
This project was bootstrapped with Create React App.
a) PROJECT SETUP:
- npm install hardhat ethers @nomiclabs/hardhat-waffle ethereum-waffle chai @nomiclabs/hardhat-ethers
waffle - https://ethereum-waffle.readthedocs.io/en/latest/ Waffle is a library for writing and testing smart contracts.
Chai - used for testing
Hardhat - https://hardhat.org/ :Hardhat Network is a local Ethereum network designed for development.
2 ) Run npx hardhat from project root new folder called hardhat and hardhat-config.js will be created
make updates to hardhat.config.js by adding: paths: { artifacts: './src/artifacts', }, networks: { hardhat: { chainId: 1337 } } 3) Under contract directory - Greeter.sol is the place where the smartcontract is defined
- Run npx hardhat compile arifacts directory would be created under src directory. Open the Greetings.json there will be a key called ABI which is : ABI stands for application binary interface. You can think of it as the interface between your client-side application and the Ethereum blockchain where the smart contract you are going to be interacting with is deployed.
Step 2:
- Deploy our smart contract to a local blockchain : Run 'npx hardhat node'
There will be 20 different account created with each account having 10000 fake ETH
Accounts Account #0: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 (10000 ETH) Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
Account #1: 0x70997970c51812dc3a010c7d01b50e0d17dc79c8 (10000 ETH) Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690d
Account #2: 0x3c44cdddb6a900fa2b585dd299e03d12fa4293bc (10000 ETH) Private Key: 0x5de4111afa1a4b94908f83103eb1f1706367c2e68ca870fc3fb9a804cdab365a
- Deploy the greeter smart contract to local blockchain network: npx hardhat run scripts/deploy.js --network localhost
Output - Greeter deployed to: 0x5FbDB2315678afecb367f032d93F642f64180aa3
This address is what we will use in our client application to talk to the smart contract. Save this address as we will need to use it when connecting to it from the client application.
-
Run npm start
-
Test it using the metamask wallet & click on the set greeting button on the UI by sending tokens to the wallet id
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
Note: this is a one-way operation. Once you eject
, you can’t go back!
If you aren’t satisfied with the build tool and configuration choices, you can eject
at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject
will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use eject
. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.