A beginner-friendly template for building applications (dApps) on Solana using Anchor and Next.js. This template implements a counter program that demonstrates essential Solana development concepts including PDAs (Program Derived Addresses), CPIs (Cross-Program Invocations), and state management.
- Node.js 18+ and pnpm
- Rust and Solana CLI tools
- Anchor Framework
- Clone the repository:
git clone <repository-url>- Install program dependencies:
cd program
pnpm install
anchor build
anchor keys sync- Install frontend dependencies:
cd frontend
pnpm install- Test the program:
cd program
anchor test- Run the frontend:
cd frontend
pnpm devprogram/programs/counter/src/lib.rs: Core program logic- Instruction handling
- PDA creation and management
- CPI implementation
frontend/components/counter/: Main dApp componentsCounterDisplay.tsx: Real-time data updatesIncrementButton.tsx&DecrementButton.tsx: Transaction handlingWalletButton.tsx: Wallet adapter button
frontend/components/counter/hooks/:useProgram.tsx: Program initialization and wallet managementuseTransactionToast.tsx: Transaction notification
-
Program Development
- PDA creation and management
- Counter state PDA
- User-specific vault PDAs
- Cross-Program Invocations (CPIs)
- Basic transfers (user to vault)
- PDA signing (vault to user)
- State management
- Initialize-if-needed pattern
- Program state updates
- PDA creation and management
-
Frontend Development
- Wallet integration and connection
- Transaction building and signing
- Account subscription for real-time updates
- Toast notifications for transaction feedback