A minimal decentralized application (DApp) that interacts with an Ethereum smart contract using MetaMask and Ethers.js.
- Connect to MetaMask
- View the welcome message from the smart contract
- Update the message on the blockchain
- Display current contract message
- Frontend deployed on Vercel
This frontend interacts with the following Solidity contract:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.26;
contract WelcomeDevelopers {
string smessage = "Welcome Developers to Ethereum !";
function getMessage() public view returns (string memory) {
return smessage;
}
function setMessage(string memory lmessage) public {
smessage = lmessage;
}
function getBalance() public view returns (uint) {
return address(this).balance;
}
}
git clone https://github.com/sumimaria/MessageDApp.git
cd MessageDApp
npm install
npx hardhat compile
First, start a local Hardhat network:
npx hardhat node
In another terminal window, deploy the contract:
npx hardhat run scripts/deploy.js --network localhost
After deployment, copy the deployed contract address. You'll use it in the frontend.
cd frontend
Update the contractAddress variable in your index.html file:
const contractAddress = "YOUR_DEPLOYED_CONTRACT_ADDRESS";
From the frontend/ folder:
npx serve .
Go to https://vercel.com
Import the GitHub repo
Click Deploy
Your frontend will be live on a Vercel URL.
MetaMask extension installed in your browser: make sure the hardhat accounts are imported in your metamask to interact with hardhat instance
Node.js and npm
Vercel account (free)