11# nextjs-anchor
22
3- Next.js starter with Tailwind CSS, ` @solana/react-hooks ` , and an Anchor vault program example.
3+ Next.js starter with Tailwind CSS, ` @solana/kit ` , and an Anchor vault program example.
44
55## Getting Started
66
@@ -9,43 +9,90 @@ npx -y create-solana-dapp@latest -t solana-foundation/templates/kit/nextjs-ancho
99```
1010
1111``` shell
12- npm install # Builds program and generates client automatically
12+ npm install
13+ npm run setup # Builds the Anchor program and generates the TypeScript client
1314npm run dev
1415```
1516
16- Open [ http://localhost:3000 ] ( http://localhost:3000 ) , connect your wallet, and interact with the vault on devnet .
17+ Open [ http://localhost:3000 ] ( http://localhost:3000 ) , connect your wallet, and interact with the vault.
1718
1819## What's Included
1920
20- - ** Wallet connection** via ` @solana/react-hooks ` with auto-discovery
21- - ** SOL Vault program** - deposit and withdraw SOL from a personal PDA vault
22- - ** Codama-generated client** - type-safe program interactions using ` @solana/kit `
23- - ** Tailwind CSS v4** with light/dark mode
21+ - ** Wallet connection** via wallet-standard with auto-discovery and dropdown UI
22+ - ** Cluster switching** — devnet, testnet, mainnet, and localnet from the header
23+ - ** Wallet balance** display with airdrop button (devnet/testnet/localnet)
24+ - ** SOL Vault program** — deposit and withdraw SOL from a personal PDA vault
25+ - ** Toast notifications** with explorer links for every transaction
26+ - ** Error handling** — human-readable messages for common Solana and program errors
27+ - ** Codama-generated client** — type-safe program interactions using ` @solana/kit `
28+ - ** Tailwind CSS v4** with light/dark mode toggle
2429
2530## Stack
2631
27- | Layer | Technology |
28- | -------------- | --------------------------------------- |
29- | Frontend | Next.js 16, React 19, TypeScript |
30- | Styling | Tailwind CSS v4 |
31- | Solana Client | ` @solana/client ` , ` @solana/react-hooks ` |
32- | Program Client | Codama-generated, ` @solana/kit ` |
33- | Program | Anchor (Rust) |
32+ | Layer | Technology |
33+ | -------------- | -------------------------------- |
34+ | Frontend | Next.js 16, React 19, TypeScript |
35+ | Styling | Tailwind CSS v4 |
36+ | Solana Client | ` @solana/kit ` , wallet-standard |
37+ | Program Client | Codama-generated, ` @solana/kit ` |
38+ | Program | Anchor (Rust) |
3439
3540## Project Structure
3641
3742```
3843├── app/
3944│ ├── components/
40- │ │ ├── providers.tsx # Solana client setup
41- │ │ └── vault-card.tsx # Vault deposit/withdraw UI
42- │ ├── generated/vault/ # Codama-generated program client
43- │ └── page.tsx # Main page
44- ├── anchor/ # Anchor workspace
45- │ └── programs/vault/ # Vault program (Rust)
46- └── codama.json # Codama client generation config
45+ │ │ ├── cluster-context.tsx # Cluster state (React context + localStorage)
46+ │ │ ├── cluster-select.tsx # Cluster switcher dropdown
47+ │ │ ├── grid-background.tsx # Solana-branded decorative grid
48+ │ │ ├── providers.tsx # Wallet + theme providers
49+ │ │ ├── theme-toggle.tsx # Light/dark mode toggle
50+ │ │ ├── vault-card.tsx # Vault deposit/withdraw UI
51+ │ │ └── wallet-button.tsx # Wallet connect/disconnect dropdown
52+ │ ├── generated/vault/ # Codama-generated program client
53+ │ ├── lib/
54+ │ │ ├── wallet/ # Wallet-standard connection layer
55+ │ │ │ ├── types.ts # Wallet types
56+ │ │ │ ├── standard.ts # Wallet discovery + session creation
57+ │ │ │ ├── signer.ts # WalletSession → TransactionSigner
58+ │ │ │ └── context.tsx # WalletProvider + useWallet() hook
59+ │ │ ├── hooks/
60+ │ │ │ ├── use-balance.ts # SWR-based balance fetching
61+ │ │ │ └── use-send-transaction.ts # Transaction send with loading state
62+ │ │ ├── cluster.ts # Cluster endpoints + RPC factory
63+ │ │ ├── lamports.ts # SOL/lamports conversion
64+ │ │ ├── send-transaction.ts # Transaction build + sign + send pipeline
65+ │ │ ├── errors.ts # Transaction error parsing
66+ │ │ └── explorer.ts # Explorer URL builder + address helpers
67+ │ └── page.tsx # Main page
68+ ├── anchor/ # Anchor workspace
69+ │ └── programs/vault/ # Vault program (Rust)
70+ └── codama.json # Codama client generation config
4771```
4872
73+ ## Local Development
74+
75+ To test against a local validator instead of devnet:
76+
77+ 1 . ** Start a local validator**
78+
79+ ``` bash
80+ solana-test-validator
81+ ```
82+
83+ 2 . ** Deploy the program locally**
84+
85+ ``` bash
86+ solana config set --url localhost
87+ cd anchor
88+ anchor build
89+ anchor deploy
90+ cd ..
91+ npm run codama:js # Regenerate client with local program ID
92+ ```
93+
94+ 3 . ** Switch to localnet** in the app using the cluster selector in the header.
95+
4996## Deploy Your Own Vault
5097
5198The included vault program is already deployed to devnet. To deploy your own:
@@ -111,8 +158,8 @@ This uses [Codama](https://github.com/codama-idl/codama) to generate a type-safe
111158
112159## Learn More
113160
114- - [ Solana Docs] ( https://solana.com/docs ) - core concepts and guides
115- - [ Anchor Docs] ( https://www.anchor-lang.com/docs ) - program development framework
116- - [ Deploying Programs] ( https://solana.com/docs/programs/deploying ) - deployment guide
117- - [ framework- kit] ( https://github.com/solana-foundation/framework- kit ) - the React hooks used here
118- - [ Codama] ( https://github.com/codama-idl/codama ) - client generation from IDL
161+ - [ Solana Docs] ( https://solana.com/docs ) — core concepts and guides
162+ - [ Anchor Docs] ( https://www.anchor-lang.com/docs/introduction ) — program development framework
163+ - [ Deploying Programs] ( https://solana.com/docs/programs/deploying ) — deployment guide
164+ - [ @ solana/ kit] ( https://github.com/anza-xyz/ kit ) — Solana JavaScript SDK
165+ - [ Codama] ( https://github.com/codama-idl/codama ) — client generation from IDL
0 commit comments