Skip to content

Commit 477e41c

Browse files
committed
readme
1 parent d78fa25 commit 477e41c

File tree

1 file changed

+82
-19
lines changed

1 file changed

+82
-19
lines changed

README.md

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,65 @@
11
# Solana Counter dApp Template
22

3-
A beginner-friendly template for building applications (dApps) on Solana using Anchor and Next.js. This template implements a simple counter program with increment and decrement instructions to demonstrate core concepts of Solana development.
3+
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.
44

5-
This template is for educational purposes and set up for devnet use.
5+
This template is for educational purposes and set up for devnet use only.
66

77
## 🎓 Educational Purpose
88

9-
This template is designed to demonstrate the basics basics of:
9+
This template is designed for developers who want to learn:
1010

1111
- How to build Solana programs using the Anchor framework
12+
- How to work with PDAs for state management and program signing
13+
- How to perform Cross-Program Invocations (CPIs)
1214
- How to create frontends that interact with Solana programs
15+
- How to handle wallet connections and transactions on a frontend
16+
17+
## 📝 Program Overview
18+
19+
The Solana program in this template demonstrates several core concepts through a simple counter application:
20+
21+
### Program Derived Addresses (PDAs)
22+
23+
1. **Counter PDA**
24+
25+
- Stores the counter's current value
26+
- Derived using the seed "counter"
27+
- Global state accessible to all users
28+
- Automatically initialized on first increment
29+
30+
2. **Vault PDA**
31+
- Holds SOL tokens from user transactions
32+
- Derived using:
33+
- Seed "vault"
34+
- User's public key
35+
- Each user gets their own vault
36+
- Demonstrates using PDAs for CPI signing
37+
38+
### Instructions
39+
40+
1. **Increment**
41+
42+
- Increases counter value by 1
43+
- Performs CPI to transfer 0.001 SOL from user to vault
44+
- Creates counter PDA if it doesn't exist
45+
- Demonstrates:
46+
- PDA initialization
47+
- System program CPI for SOL transfer
48+
- State management
49+
50+
2. **Decrement**
51+
- Decreases counter value by 1
52+
- Performs CPI to transfer 0.001 SOL from vault back to user
53+
- Demonstrates:
54+
- PDA signing (vault)
55+
- System program CPI with PDA as signer
56+
57+
### Cross-Program Invocations (CPIs)
58+
59+
The program demonstrates CPIs through SOL transfers:
60+
61+
- User → Vault (increment): Basic CPI to system program
62+
- Vault → User (decrement): CPI with PDA signing
1363

1464
## 🏗 Project Structure
1565

@@ -29,14 +79,15 @@ This template is designed to demonstrate the basics basics of:
2979

3080
1. **Solana Program**
3181

32-
- Simple counter with increment/decrement instructions
33-
- PDA (Program Derived Address) for counter state management and CPI signing
34-
- CPI (Cross Program Invocation) for SOL transfers on increment/decrement
82+
- Counter state management using PDA
83+
- Vault system using user-specific PDAs
84+
- SOL transfer demonstration using CPIs
85+
- PDA initialization and signing
3586

3687
2. **Frontend Application**
3788
- Wallet adapter integration
38-
- Integrated to invoke the counter program
3989
- Real-time counter updates
90+
- Transaction toast notifications
4091
- UI with Tailwind CSS and shadcn/ui
4192

4293
## 🚀 Getting Started
@@ -49,7 +100,13 @@ This template is designed to demonstrate the basics basics of:
49100

50101
### Installation
51102

52-
1. Install program dependencies:
103+
1. Clone the repository:
104+
105+
```bash
106+
git clone <repository-url>
107+
```
108+
109+
2. Install program dependencies:
53110

54111
```bash
55112
cd program
@@ -58,7 +115,7 @@ anchor build
58115
anchor keys sync
59116
```
60117

61-
2. Install frontend dependencies:
118+
3. Install frontend dependencies:
62119

63120
```bash
64121
cd frontend
@@ -86,33 +143,39 @@ pnpm dev
86143
### Program (Smart Contract)
87144

88145
- `program/programs/counter/src/lib.rs`: Core program logic
89-
- Learn about Anchor program structure
90-
- Understand account management
91-
- See how to handle program instructions
146+
- Instruction handling
147+
- PDA creation and management
148+
- CPI implementation
92149

93150
### Frontend Components
94151

95152
- `frontend/components/counter/`: Main dApp components
96153
- `CounterDisplay.tsx`: Real-time data updates
97154
- `IncrementButton.tsx` & `DecrementButton.tsx`: Transaction handling
98-
- `WalletButton.tsx`: Wallet connection management
155+
- `WalletButton.tsx`: Wallet adapter button
99156

100157
### Custom Hooks
101158

102159
- `frontend/components/counter/hooks/`:
103160
- `useProgram.tsx`: Program initialization and wallet management
104-
- `useTransactionToast.tsx`: Transaction notification handling
161+
- `useTransactionToast.tsx`: Transaction notification
105162

106163
## 🔍 Key Concepts Demonstrated
107164

108165
1. **Program Development**
109166

110-
- PDA (Program Derived Address) creation and management
111-
- State management in Solana programs
112-
- Cross-Program Invocation (CPI) for SOL transfers and PDA signing
167+
- PDA creation and management
168+
- Counter state PDA
169+
- User-specific vault PDAs
170+
- Cross-Program Invocations (CPIs)
171+
- Basic transfers (user to vault)
172+
- PDA signing (vault to user)
173+
- State management
174+
- Initialize-if-needed pattern
175+
- Program state updates
113176

114177
2. **Frontend Development**
115-
116-
- Wallet integration and connection management
178+
- Wallet integration and connection
117179
- Transaction building and signing
118180
- Account subscription for real-time updates
181+
- Toast notifications for transaction feedback

0 commit comments

Comments
 (0)