A simple decentralized Counter Application built using React, Ethers.js, Solidity, and MetaMask. Users can increase, decrease, and reset a counter stored on the Ethereum blockchain.
- Connects to Ethereum using MetaMask
- Reads counter value directly from a smart contract
- Increase counter value
- Decrease counter value
- Reset counter to zero
- Real-time UI updates after blockchain transactions
- React.js
- Tailwind CSS
- Ethers.js
- Solidity
- Ethereum
- MetaMask
- Remix IDE
src/
│
├── Components/
│ └── Counter.jsx
│
├── Contract/
│ ├── ABI.js
│ └── ContractAddress.js
│
├── App.jsx
└── main.jsx// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Counter {
uint256 public counter;
constructor() {
counter = 0;
}
function onclickincrease() public {
counter++;
}
function onclickdecrease() public {
require(counter > 0, "Counter is already zero");
counter--;
}
function onclickzero() public {
counter = 0;
}
}git clone https://github.com/yourusername/counter-dapp.git
cd counter-dappnpm installnpm run dev- Open Remix IDE.
- Create
Counter.sol. - Paste the smart contract code.
- Compile using Solidity 0.8.20.
- Connect MetaMask.
- Select Sepolia Testnet.
- Deploy the contract.
- Copy the Contract Address.
- Copy the Contract ABI.
export const contractAddress = "YOUR_CONTRACT_ADDRESS";export const contractABI = [
// Paste ABI here
];- Install MetaMask.
- Create or import a wallet.
- Switch to Sepolia Testnet.
- Get Sepolia ETH from a faucet.
- Connect your wallet to the DApp.
await contract.onclickincrease();Increases the counter value by 1.
await contract.onclickdecrease();Decreases the counter value by 1.
await contract.onclickzero();Resets the counter to 0.
await contract.counter();Fetches the current counter value from the blockchain.
10
[-] [Reset] [+]
Decrease Reset Increase
This project helped me learn:
- Solidity Smart Contract Development
- Smart Contract Deployment with Remix
- MetaMask Integration
- Ethers.js Fundamentals
- Reading Blockchain Data
- Sending Transactions
- React State Management
- Web3 Frontend Development
- Wallet Connect Button
- Event Logging
- Transaction History
- User-Specific Counters
- Counter Ownership
- Better UI/UX
- Dark Mode Support
Kartik Singh
Aspiring Web3 Developer focused on React, Solidity, and Blockchain Development.
If you found this project useful, consider giving it a ⭐ on GitHub.
It helps support future Web3 and Blockchain projects.
#Web3 #Solidity #React #Ethereum #Blockchain #EthersJS #MetaMask #DApp