A robust and simple counter smart contract built on the Stacks Blockchain using Clarity. This project demonstrates fundamental smart contract development patterns and serves as an educational example for blockchain developers.
- Simple Counter Logic: Increment, decrement, and read counter values
- Blockchain Persistence: State stored immutably on the Stacks network
- Comprehensive Testing: Full test suite with Vitest
- Multi-Network Support: Configurations for Devnet, Testnet, and Mainnet
- Developer-Friendly: Built with Clarinet for easy development and deployment
- Clarinet (latest version)
- Node.js 16+ and npm
- Git
-
Clone the repository
git clone https://github.com/stx-labs/clarinet.git cd clarinet/counter-contract -
Install dependencies
npm install
-
Verify setup
clarinet check
Start the Clarinet console for interactive testing:
clarinet consoleThe contract provides three main functions:
read-counter(): Returns the current counter valueincrement(): Increases the counter by 1decrement(): Decreases the counter by 1 (minimum value: 0)
;; Read current counter value
(read-counter)
;; Increment counter
(increment)
;; Decrement counter
(decrement)Run the comprehensive test suite:
npm testRun tests in watch mode:
npm run test:watchView test coverage:
npm run test:coverage-
Start Devnet:
clarinet devnet start
-
Deploy contract:
clarinet deployments generate --devnet clarinet deployments apply --devnet
Update settings/Testnet.toml or settings/Mainnet.toml with your wallet information, then:
clarinet deployments generate --testnet
clarinet deployments apply --testnetReturns the current counter value.
Returns: uint - Current counter value
Increments the counter by 1.
Returns: bool - Success status
Decrements the counter by 1 (if current value > 0).
Returns: bool - Success status
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow Clarity best practices
- Add tests for new functionality
- Update documentation as needed
- Ensure all tests pass before submitting PR
This project is licensed under the MIT License - see the LICENSE file for details.
- 📧 Email: support@hirosystems.com
- 💬 Discord: Join our community
- 📖 Documentation: Stacks Docs
- 🐛 Issues: Report bugs
Built with ❤️ by the Stacks Community