๐งฎ Simple Solana Counter Program
A lightweight, native Solana smart contract for incrementing and decrementing a counter. Developed with native Rust for performance and simplicity.
๐ GitHub Repository This project demonstrates a minimalistic Solana on-chain program (smart contract) written in native Rust. The core functionality revolves around managing a simple counter:
- ๐ Increment the counter by sending a transaction
- ๐ Decrement the counter similarly
- ๐ State is stored on-chain and owned by the user's keypair
- โ๏ธ Built using low-level Solana primitives (no Anchor framework on-chain) โ excellent for learning core Solana mechanics
The program is ideal for developers who want to:
- Understand how to work with Solanaโs native runtime
- Learn the basics of account handling, transaction flow, and state management
- Use it as a boilerplate to build more complex programs
๐ ๏ธ How to Get Started
1. ๐งช Start a Local Solana Validator
Run the following command to simulate the Solana blockchain locally:
solana-test-validator
2. ๐งฑ Build and Deploy the Program
Use Anchor CLI to build and deploy the smart contract to the local validator:
anchor build && anchor deploy
Note: Although the on-chain code is native Rust, Anchor is used for deployment and local testing convenience.
3. ๐ Set Up Your Wallet
Export your Solana CLI wallet path so it can be used for deployments and interactions:
export ANCHOR_WALLET=~/.config/solana/id.json
4. ๐ Interact with the Program
Once deployed, you can send transactions to:
- Increment the stored counter
- Decrement the counter
- Fetch and log the current value
These actions can be scripted in TypeScript/JavaScript using Anchor client or done manually with solana
CLI.
๐ License
This project is open-source and available under the terms of the MIT License. Feel free to fork, modify, and use it for both personal and commercial purposes.