Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Solana development skill covering @solana/kit v5, Anchor programs, LiteSVM testing, and security patterns.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/frontend-framework-kit.md
1---2title: Frontend with framework-kit3description: Build React and Next.js Solana apps with a single client instance, Wallet Standard-first connection, and minimal client-side footprint.4---56# Frontend with framework-kit (Next.js / React)78## Goals9- One Solana client instance for the app (RPC + WS + wallet connectors)10- Wallet Standard-first discovery/connect11- Minimal "use client" footprint in Next.js (hooks only in leaf components)12- Transaction sending that is observable, cancelable, and UX-friendly1314## Recommended dependencies15- @solana/client16- @solana/react-hooks17- @solana/kit18- @solana-program/system, @solana-program/token, etc. (only what you need)1920## Bootstrap recommendation21Prefer `create-solana-dapp` and pick a kit/framework-kit compatible template for new projects.2223## Provider setup (Next.js App Router)24Create a single client and provide it via SolanaProvider.2526Example `app/providers.tsx`:2728```tsx29'use client';3031import React from 'react';32import { SolanaProvider } from '@solana/react-hooks';33import { autoDiscover, createClient } from '@solana/client';3435const endpoint =36process.env.NEXT_PUBLIC_SOLANA_RPC_URL ?? 'https://api.devnet.solana.com';3738// Some environments prefer an explicit WS endpoint; default to wss derived from https.39const websocketEndpoint =40process.env.NEXT_PUBLIC_SOLANA_WS_URL ??41endpoint.replace('https://', 'wss://').replace('http://', 'ws://');4243export const solanaClient = createClient({44endpoint,45websocketEndpoint,46walletConnectors: autoDiscover(),47});4849export function Providers({ children }: { children: React.ReactNode }) {50return <SolanaProvider client={solanaClient}>{children}</SolanaProvider>;51}52```5354Then wrap `app/layout.tsx` with `<Providers>`.5556## Hook usage patterns (high-level)5758Prefer framework-kit hooks before writing your own store/subscription logic:5960* `useWalletConnection()` for connect/disconnect and wallet discovery61* `useBalance(...)` for lamports balance62* `useSolTransfer(...)` for SOL transfers63* `useSplToken(...)` / token helpers for token balances/transfers64* `useTransactionPool(...)` for managing send + status + retry flows6566When you need custom instructions, build them using `@solana-program/*` and send them via the framework-kit transaction helpers.6768## Data fetching and subscriptions6970* Prefer watchers/subscriptions rather than manual polling.71* Clean up subscriptions with abort handles returned by watchers.72* For Next.js: keep server components server-side; only leaf components that call hooks should be client components.7374## Transaction UX checklist7576* Disable inputs while a transaction is pending77* Provide a signature immediately after send78* Track confirmation states (processed/confirmed/finalized) based on UX need79* Show actionable errors:8081* user rejected signing82* insufficient SOL for fees / rent83* blockhash expired / dropped84* account already in use / already initialized85* program error (custom error code)8687## When to use ConnectorKit (optional)8889If you need a headless connector with composable UI elements and explicit state control, use ConnectorKit.90Typical reasons:9192* You want a headless wallet connection core (useful across frameworks)93* You want more control over wallet/account state than a single provider gives94* You need production diagnostics/health checks for wallet sessions95