Counter Smart Contract
Counter is a simple and interactive Solidity smart contract deployed on the Ethereum blockchain. It allows users to increment, decrement, reset, and view a counter value, demonstrating the fundamental
Description
πΏ Counter Smart Contract
Counter is a simple and interactive Solidity smart contract deployed on the Ethereum blockchain. It allows users to increment, decrement, reset, and view a counter value, demonstrating the fundamentals of smart contract development.
π Live Deployment
Blockchain: Ethereum (Testnet/Mainnet)
Deployed Contract Address: 0xd9145CCE52D386f254917e481eB44e9943F39138
Transaction Hash: 0xb2f47b8afc05ecfb893170268a53677a20f41420120b5788707a91a59d62f6f3
Transaction Cost: 262,466 gas β Successfully deployed and verified.
β¨ Features
πΌ Increment Counter β Increase the counter by 1.
π½ Decrement Counter β Decrease the counter by 1 (cannot go below zero).
π Reset Counter β Reset the counter to 0.
π View Count β Check the current value of the counter.
π Events β Emits CountChanged event whenever the counter changes.
β How It Works
Increment Counter
increment(); Adds 1 to the current counter and emits a CountChanged event.
Decrement Counter
decrement(); Subtracts 1 from the counter (only if above zero) and emits a CountChanged event.
Reset Counter
reset(); Sets the counter value to 0 and emits a CountChanged event. Get Current Count
getCount(); Returns the current counter value.
π Project Structure
counter/ βββ contracts/ β βββ Counter.sol # Smart contract code βββ scripts/ β βββ deploy.js # Optional deployment script βββ test/ β βββ counter.test.js # Automated tests βββ README.md βββ hardhat.config.js # Hardhat configuration βββ package.json
π§ͺ Installation & Testing
Prerequisites
Node.js v16+
Hardhat
MetaMask (for testnet interaction)
Steps git clone https://github.com/yourusername/counter.git cd counter npm install npx hardhat compile npx hardhat test
Deployment (Optional) npx hardhat run scripts/deploy.js --network
π Contract Function Summary
Function | Description | Access |
|---|---|---|
| Increase counter by 1 | Public |
| Decrease counter by 1 (cannot go below 0) | Public |
| Reset counter to 0 | Public |
| Get current counter value | Public View |
π Real-World Use Cases
Educational tool for learning Solidity basics Demonstration of smart contract events Interactive blockchain applications for testing and experimentation
π License
MIT License β Free to use, modify, and distribute.
π€ Contributing
We welcome contributions from the community! Fork the repo Create your branch: git checkout -b feature/xyz Commit your changes: git commit -m "Add feature" Push to the branch: git push origin feature/xyz Submit a Pull Request
π Contact
Owner: Tamal Kar π§ Email: tamal151947@example.com
π± Counter Smart Contract β Learn, interact, and experiment with blockchain in a simple way.
