Deployed Frontend URL: LINK
Solana Program ID: ID
A simple decentralized counter application built on Solana. Users can create personal counters, increment them, and reset them to zero. Each user has their own counter account derived from their wallet address, ensuring data isolation and ownership. This dApp demonstrates basic Solana program development concepts including PDAs, account creation, and state management.
- Create Counter: Initialize a new counter account for your wallet
- Increment Counter: Add 1 to your personal counter value
- Reset Counter: Set your counter back to 0
- View Counter: Display current counter value and owner information
- Connect Wallet - Connect your Solana wallet
- Initialize Counter - Click "Create Counter" to set up your personal counter account
- Increment - Use the "+" button to increase your counter value
- Reset - Click "Reset" to set your counter back to 0
- View Stats - See your current count and total increments made
The Counter dApp uses a simple architecture with one main account type and three core instructions. The program leverages PDAs to create unique counter accounts for each user, ensuring data isolation and preventing conflicts between different users' counters.
The program uses Program Derived Addresses to create deterministic counter accounts for each user.
PDAs Used:
- Counter PDA: Derived from seeds
["counter", user_wallet_pubkey]- ensures each user has a unique counter account that only they can modify
Instructions Implemented:
- Initialize: Creates a new counter account for the user with initial value of 0
- Increment: Increases the counter value by 1 and tracks total increments
- Reset: Sets the counter value back to 0 while preserving the owner information
#[account]
pub struct Counter {
pub owner: Pubkey, // The wallet that owns this counter
pub count: u64, // Current counter value
pub total_increments: u64, // Total number of times incremented (persists through resets)
pub created_at: i64, // Unix timestamp when counter was created
}Comprehensive test suite covering all instructions with both successful operations and error conditions to ensure program security and reliability.
Happy Path Tests:
- Initialize Counter: Successfully creates a new counter account with correct initial values
- Increment Counter: Properly increases count and total_increments by 1
- Reset Counter: Sets count to 0 while preserving owner and total_increments
Unhappy Path Tests:
- Initialize Duplicate: Fails when trying to initialize a counter that already exists
- Increment Unauthorized: Fails when non-owner tries to increment someone else's counter
- Reset Unauthorized: Fails when non-owner tries to reset someone else's counter
- Account Not Found: Fails when trying to operate on non-existent counter
yarn install # install dependencies
anchor test # run testsThis was my first Solana dApp and the learning curve was steep! The biggest challenges were figuring out account ownership validation (kept getting unauthorized errors) and dealing with async transaction confirmations. PDAs were confusing at first but once they clicked, the deterministic addressing made everything much cleaner.