Skip to content

Commit d78fa25

Browse files
committed
refactor
1 parent 03e43af commit d78fa25

File tree

6 files changed

+1683
-1163
lines changed

6 files changed

+1683
-1163
lines changed

README.md

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Solana Counter dApp Template
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.
4+
5+
This template is for educational purposes and set up for devnet use.
6+
7+
## 🎓 Educational Purpose
8+
9+
This template is designed to demonstrate the basics basics of:
10+
11+
- How to build Solana programs using the Anchor framework
12+
- How to create frontends that interact with Solana programs
13+
14+
## 🏗 Project Structure
15+
16+
```
17+
├── program/ # Solana program (smart contract)
18+
│ ├── programs/ # Program source code
19+
│ ├── tests/ # Program tests
20+
│ └── Anchor.toml # Anchor configuration
21+
22+
└── frontend/ # Next.js frontend
23+
├── app/ # app router page and layout
24+
├── components/ # React components
25+
└── anchor-idl/ # Program IDL
26+
```
27+
28+
## 🔧 Core Features
29+
30+
1. **Solana Program**
31+
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
35+
36+
2. **Frontend Application**
37+
- Wallet adapter integration
38+
- Integrated to invoke the counter program
39+
- Real-time counter updates
40+
- UI with Tailwind CSS and shadcn/ui
41+
42+
## 🚀 Getting Started
43+
44+
### Prerequisites
45+
46+
- Node.js 18+ and pnpm
47+
- Rust and Solana CLI tools
48+
- Anchor Framework
49+
50+
### Installation
51+
52+
1. Install program dependencies:
53+
54+
```bash
55+
cd program
56+
pnpm install
57+
anchor build
58+
anchor keys sync
59+
```
60+
61+
2. Install frontend dependencies:
62+
63+
```bash
64+
cd frontend
65+
pnpm install
66+
```
67+
68+
### Development
69+
70+
1. Test the program:
71+
72+
```bash
73+
cd program
74+
anchor test
75+
```
76+
77+
2. Run the frontend:
78+
79+
```bash
80+
cd frontend
81+
pnpm dev
82+
```
83+
84+
## 💡 Learning Resources
85+
86+
### Program (Smart Contract)
87+
88+
- `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
92+
93+
### Frontend Components
94+
95+
- `frontend/components/counter/`: Main dApp components
96+
- `CounterDisplay.tsx`: Real-time data updates
97+
- `IncrementButton.tsx` & `DecrementButton.tsx`: Transaction handling
98+
- `WalletButton.tsx`: Wallet connection management
99+
100+
### Custom Hooks
101+
102+
- `frontend/components/counter/hooks/`:
103+
- `useProgram.tsx`: Program initialization and wallet management
104+
- `useTransactionToast.tsx`: Transaction notification handling
105+
106+
## 🔍 Key Concepts Demonstrated
107+
108+
1. **Program Development**
109+
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
113+
114+
2. **Frontend Development**
115+
116+
- Wallet integration and connection management
117+
- Transaction building and signing
118+
- Account subscription for real-time updates

program/Anchor.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[toolchain]
2-
package_manager = "yarn"
2+
package_manager = "pnpm"
33

44
[features]
55
resolution = true
66
skip-lint = false
77

88
[programs.localnet]
9-
counter = "C8ELYscK1BFKCPyo8cj3NQq5UexGxmAXpJeqsfLhANU4"
9+
counter = "8PY1q5J3Aq2z7TBDLBrVjv77mYzjXSCz6iHQaFEFw9hY"
1010

1111
[registry]
1212
url = "https://api.apr.dev"
1313

1414
[provider]
15-
cluster = "localnet"
15+
cluster = "devnet"
1616
wallet = "~/.config/solana/id.json"
1717

1818
[scripts]

0 commit comments

Comments
 (0)