The files index.js, MySmartContract.sol, and deploy.js contain codes to practice interaction with the SmartContract_with_Front_end_interaction smart contract through a website.
deploy.js file contains the code of frontend.
Follow the steps below:
-
Clone this repository or download the zip file and then extract it.
-
Above repository contains all necessary files to interact with our smart contract called
SmartContract_with_Front_end_interaction.sol. -
Copy
index.jscontents from this repository to theindex.jsfile in thepagesfolder. -
Copy
deploy.jscontents from this repository to thedeploy.jsfile in thescriptsfolder. -
Install MetaMask Browser Extension.
After cloning GitHub, you will want to do the following to get the code running on your computer.
-
Inside the project directory, in the terminal type:
npm i -
Open two additional terminals in your VS code.
-
In the second terminal, type:
npx hardhat node -
In the third terminal, type:
npx hardhat run --network localhost scripts/deploy.js(Note: You can also verify the address of deployment in thecontractAddressvariable inindex.jsfile) -
Back in the first terminal, type
npm run devto launch the frontend.
After this, the project will be running on your local host, typically at http://localhost:3000/.
To interact with the smart contract locally, we need to set up a local network with the MetaMask wallet.
-
Click on the MetaMask extension and then click on the top middle button, which is the network selection button.
-
Click on "Add a Network."
-
Click on "Add a Network Manually."
-
Give the Network name (whatever you want).
-
Set the New RPC URL to
http://127.0.0.1:8545/. -
Set the Chain ID to
31337. -
Set the Currency symbol to
ETH. -
Now, set the MetaMask wallet network to the newly created local network.
To set up an account, you have to import an account with the account's private key, which you can find in the second terminal where we executed the command npx hardhat node. After hitting enter, you can see there are many account numbers with private keys written in the terminal. Just take any account's corresponding private key to import it to your Metamask Wallet.
Head to http://localhost:3000/ to start interacting with the Metamask Wallet.
You can also see all transaction details in the deploy terminal.
This project is licensed under the MIT License. See the LICENSE file for details.