You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82-19Lines changed: 82 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,65 @@
1
1
# Solana Counter dApp Template
2
2
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.
4
4
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.
6
6
7
7
## 🎓 Educational Purpose
8
8
9
-
This template is designed to demonstrate the basics basics of:
9
+
This template is designed for developers who want to learn:
10
10
11
11
- 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)
12
14
- 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
13
63
14
64
## 🏗 Project Structure
15
65
@@ -29,14 +79,15 @@ This template is designed to demonstrate the basics basics of:
29
79
30
80
1.**Solana Program**
31
81
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
35
86
36
87
2.**Frontend Application**
37
88
- Wallet adapter integration
38
-
- Integrated to invoke the counter program
39
89
- Real-time counter updates
90
+
- Transaction toast notifications
40
91
- UI with Tailwind CSS and shadcn/ui
41
92
42
93
## 🚀 Getting Started
@@ -49,7 +100,13 @@ This template is designed to demonstrate the basics basics of:
49
100
50
101
### Installation
51
102
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:
53
110
54
111
```bash
55
112
cd program
@@ -58,7 +115,7 @@ anchor build
58
115
anchor keys sync
59
116
```
60
117
61
-
2. Install frontend dependencies:
118
+
3. Install frontend dependencies:
62
119
63
120
```bash
64
121
cd frontend
@@ -86,33 +143,39 @@ pnpm dev
86
143
### Program (Smart Contract)
87
144
88
145
-`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
92
149
93
150
### Frontend Components
94
151
95
152
-`frontend/components/counter/`: Main dApp components
0 commit comments