-
Notifications
You must be signed in to change notification settings - Fork 266
docs: updat frontend guide to show new libraries #968
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GuiBibeau
wants to merge
11
commits into
main
Choose a base branch
from
react-hooks-docs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
42bc2cb
docs: update Next.js frontend guide to use @solana/react-hooks
GuiBibeau 966fd92
docs: rename kit.mdx to nextjs-solana.mdx for clearer routing
GuiBibeau cb14950
docs: update frontend navigation to reference nextjs-solana
GuiBibeau 1ec9b00
Update Next.js Solana tutorial for SOL transfers
GuiBibeau e4355ca
docs(frontend): add kit client guides
GuiBibeau 547e31b
chore(frontend): tweak index copy
GuiBibeau 9a7c6a7
docs(frontend): simplify nextjs react hooks guide
GuiBibeau 9aa76d6
docs(frontend): nudge towards react hooks
GuiBibeau fc1d1ae
Merge remote-tracking branch 'origin/main' into react-hooks-docs
GuiBibeau 3637030
feat: code review items
GuiBibeau f56d3c5
fix: Simplify tutorial and fix kit installation
GuiBibeau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "title": "الواجهة الأمامية", | ||
| "pages": ["kit"] | ||
| "pages": ["nextjs-solana"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "title": "Frontend", | ||
| "pages": ["kit"] | ||
| "pages": ["nextjs-solana"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| { | ||
| "title": "Frontend", | ||
| "pages": ["kit"] | ||
| "pages": ["nextjs-solana"] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| --- | ||
| title: "@solana/client" | ||
| description: Build lean Solana frontends with the headless Solana client runtime. | ||
| --- | ||
|
|
||
| `@solana/client` keeps the runtime surface lean. One store, one RPC stack, and a wallet registry power | ||
| the different helpers so the same instance can back CLIs, scripts, or full UIs. Actions, watchers, and | ||
| helpers all share cache, subscriptions, and wallet sessions through that single client. | ||
|
|
||
| <Callout type="info"> | ||
| When you are building a purely React experience it is usually faster to start with | ||
| [`@solana/react-hooks`](/docs/frontend/react-hooks). The hooks package wraps this same client runtime and | ||
| exposes ready-made hooks so you only drop to the headless client when you need extra control. | ||
| </Callout> | ||
|
|
||
| ## Install | ||
|
|
||
| ```terminal | ||
| $ npm install @solana/client | ||
| ``` | ||
|
|
||
| Use any package manager; the client runs in browsers, workers, React, Svelte, or server-side runtimes. | ||
|
|
||
| ## Create a client once | ||
|
|
||
| Choose Wallet Standard connectors (auto discovery is the fastest way to start), then create the client. | ||
| This single object exposes the store, actions, watchers, and helpers. | ||
|
|
||
| ```ts | ||
| import { autoDiscover, createClient } from "@solana/client"; | ||
|
|
||
| const client = createClient({ | ||
| endpoint: "https://api.devnet.solana.com", | ||
| websocketEndpoint: "wss://api.devnet.solana.com", | ||
| walletConnectors: autoDiscover(), | ||
| }); | ||
|
|
||
| await client.actions.connectWallet("wallet-standard:phantom"); | ||
| const balance = await client.actions.fetchBalance("Fke...address"); | ||
| console.log(balance.lamports?.toString()); | ||
| ``` | ||
|
|
||
| The client store tracks cluster config, subscriptions, pending transactions, and wallet sessions. You can | ||
| provide your own Zustand store if you need persistence or multi-tab coordination. | ||
|
|
||
| ## Wallet orchestration | ||
|
|
||
| Connectors encapsulate Wallet Standard metadata plus connect/disconnect logic. Register the built-in | ||
| `phantom()`, `solflare()`, `backpack()`, or `autoDiscover()` helpers, or wrap custom providers with | ||
| `createWalletStandardConnector`. All wallet actions (connect, disconnect, sign, send) flow through the | ||
| client registry so every consumer stays in sync. | ||
|
|
||
| ## Actions, watchers, and helpers | ||
|
|
||
| - **Actions** wrap common RPC reads and writes while updating the store (e.g., `fetchAccount`, | ||
| `requestAirdrop`, `setCluster`). | ||
| - **Watchers** multiplex websocket subscriptions, stream updates into the store, and give you abort | ||
| handles for cleanup. | ||
| - **Helpers** expose higher-level flows such as SOL transfers, SPL token helpers, signature polling, and | ||
| transaction pools. | ||
|
|
||
| ```ts | ||
| const abortWatcher = client.watchers.watchBalance( | ||
| { address: "Fke...address" }, | ||
| (lamports) => { | ||
| console.log("live balance", lamports.toString()); | ||
| }, | ||
| ); | ||
|
|
||
| // Later when the component unmounts or the flow ends | ||
| abortWatcher.abort(); | ||
| ``` | ||
|
|
||
| ## Transaction helper pattern | ||
|
|
||
| The transaction helper owns blockhash refresh, fee payer resolution, and signing. You can prepare, | ||
| inspect, and send with whatever UX you prefer. | ||
|
|
||
| ```ts | ||
| const prepared = await client.helpers.transaction.prepare({ | ||
| authority: client.store.getState().wallet.session!, | ||
| instructions: [instructionA, instructionB], | ||
| }); | ||
|
|
||
| await client.helpers.transaction.simulate(prepared, { commitment: "processed" }); | ||
| const signature = await client.helpers.transaction.send(prepared); | ||
| console.log("submitted", signature.toString()); | ||
| ``` | ||
|
|
||
| Use `prepareAndSend` for a pre-built flow (simulation plus logging) or call `sign` / `toWire` to collect | ||
| signatures manually before relaying the wire format yourself. | ||
|
|
||
| ## Common patterns for Solana devs | ||
|
|
||
| - **Headless state machines**: Run the client inside API routes, scripts, or workers to reuse the same | ||
| wallet + RPC orchestration logic that powers your UI. | ||
| - **Realtime dashboards**: Combine watchers (balances, accounts, signatures) with your preferred UI | ||
| library; the client handles websocket fan-out and cache invalidation. | ||
| - **Custom stores**: Inject your own Zustand store to hydrate from IndexedDB/localStorage, mirror state to | ||
| server sessions, or coordinate between browser tabs. | ||
| - **Bridge to React hooks**: Pass a configured client instance to `@solana/react-hooks` when you want | ||
| ergonomic hooks on top of the same runtime. | ||
| - **Testability**: The single client interface can be mocked in unit tests, making it easy to simulate | ||
| RPC responses or wallet sessions without a browser wallet present. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --- | ||
| title: Frontend | ||
| description: Learn about building interfaces for Solana Programs. | ||
| --- | ||
|
|
||
| Frontend development on Solana involves working with Programs, wallets and | ||
| popular JavaScript frameworks like React. Interacting with these components | ||
| requires handling connection, transaction creation and reading from Solana | ||
| Accounts. | ||
|
|
||
| To help with this work, a variety Solana Client libraries are available in different frameworks. | ||
|
|
||
| ## Main libraries | ||
|
|
||
|
|
||
|
|
||
| <Cards> | ||
| <Card title="@solana/client" href="https://github.com/solana-foundation/framework-kit/tree/main/packages/client"> | ||
| - Simple Solana client bundling RPC, wallets, transactions | ||
| - Includes built-in state store, actions, watchers, connectors | ||
| </Card> | ||
| <Card title="@solana/react-hooks" href="https://github.com/solana-foundation/framework-kit/tree/main/packages/react-hooks"> | ||
| - Complete hooks for wallets, balances, transfers, signatures, queries | ||
| - React provider hooks wrapping `@solana/client` runtime state | ||
| </Card> | ||
| <Card title="@solana/web3-compat" href="https://github.com/solana-foundation/framework-kit/tree/main/packages/web3-compat"> | ||
| - Web3.js compatible toolkit to simplify upgrading. | ||
| - Newer internals relying on a mix of web3.js and kit. | ||
| </Card> | ||
| <Card title="@solana/kit" href="https://github.com/solana-foundation/framework-kit/tree/main/packages/web3-compat"> | ||
| - Low level Solana SDK powering the other Solana libraries like `@solana/react-hooks` | ||
| - Fully tree-shakable, uses modern web standard and powers | ||
| </Card> | ||
| </Cards> | ||
|
|
||
|
|
||
| <Callout type="warn" title="@solana/web3.js is deprecated`"> | ||
| Many Solana ecosystem projects still rely on the deprecated `@solana/web3.js`. | ||
| Prefer `@solana/web3-compat` to simplify your migration path. | ||
| </Callout> | ||
|
|
||
| - [@solana/client guide](/docs/frontend/client): lean, headless runtime for RPC, wallets, and transactions. | ||
| - [@solana/react-hooks guide](/docs/frontend/react-hooks): React hooks layered on the same client runtime. | ||
| - [@solana/web3-compat guide](/docs/frontend/web3-compat): compatibility layer to migrate from `@solana/web3.js` to Kit powered stacks. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.