@solana/react-hooks 1.1.10 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +66 -10
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -46,7 +46,7 @@ These snippets assume a parent already handled wallet connection and can pass an
46
46
 
47
47
  ```tsx
48
48
  function WalletPanel() {
49
- const { connectors, connect, disconnect, wallet, status } =
49
+ const { connectors, connect, disconnect, wallet, status, currentConnector } =
50
50
  useWalletConnection();
51
51
  const address = wallet?.account.address;
52
52
  const balance = useBalance(address);
@@ -54,6 +54,7 @@ function WalletPanel() {
54
54
  if (status === "connected") {
55
55
  return (
56
56
  <div>
57
+ <p>Connected via {currentConnector?.name}</p>
57
58
  <p>{address?.toString()}</p>
58
59
  <p>Lamports: {balance.lamports?.toString() ?? "loading…"}</p>
59
60
  <button onClick={disconnect}>Disconnect</button>
@@ -85,6 +86,24 @@ function BalanceCard({ address }: { address: string }) {
85
86
  }
86
87
  ```
87
88
 
89
+ ### Read account data (auto fetch + watch)
90
+
91
+ ```tsx
92
+ import { useAccount } from "@solana/react-hooks";
93
+
94
+ function AccountInfo({ address }: { address: string }) {
95
+ const account = useAccount(address);
96
+ if (!account || account.fetching) return <p>Loading…</p>;
97
+ return (
98
+ <div>
99
+ <p>Lamports: {account.lamports?.toString() ?? "0"}</p>
100
+ <p>Owner: {account.owner ?? "—"}</p>
101
+ <p>Slot: {account.slot?.toString() ?? "—"}</p>
102
+ </div>
103
+ );
104
+ }
105
+ ```
106
+
88
107
  ### Send SOL
89
108
 
90
109
  ```tsx
@@ -97,7 +116,7 @@ function SendSol({ destination }: { destination: string }) {
97
116
  <button
98
117
  disabled={isSending}
99
118
  onClick={() =>
100
- send({ destination, lamports: 100_000_000n /* 0.1 SOL */ })
119
+ send({ destination, amount: 100_000_000n /* 0.1 SOL */ })
101
120
  }
102
121
  >
103
122
  {isSending ? "Sending…" : "Send 0.1 SOL"}
@@ -129,7 +148,7 @@ function TokenPanel({
129
148
  <p>Balance: {balance?.uiAmount ?? "0"}</p>
130
149
  <button
131
150
  disabled={isSending || !owner}
132
- onClick={() => send({ amount: 1n, destinationOwner })}
151
+ onClick={() => send({ amount: 1n, destinationOwner, amountInBaseUnits: true })}
133
152
  >
134
153
  {isSending ? "Sending…" : "Send 1 token"}
135
154
  </button>
@@ -138,6 +157,8 @@ function TokenPanel({
138
157
  }
139
158
  ```
140
159
 
160
+ > **Note:** Use `amountInBaseUnits: true` when passing raw bigint amounts. For human-readable decimal strings like `"1.5"`, omit the flag.
161
+
141
162
  ### Fetch address lookup tables
142
163
 
143
164
  ```tsx
@@ -178,34 +199,61 @@ function NonceInfo({ address }: { address: string }) {
178
199
 
179
200
  ```tsx
180
201
  import type { TransactionInstructionInput } from "@solana/client";
181
- import { useTransactionPool } from "@solana/react-hooks";
202
+ import { useTransactionPool, useWalletSession } from "@solana/react-hooks";
182
203
 
183
204
  function TransactionFlow({ ix }: { ix: TransactionInstructionInput }) {
184
- const pool = useTransactionPool();
205
+ const session = useWalletSession();
206
+ const {
207
+ addInstruction,
208
+ prepareAndSend,
209
+ isSending,
210
+ sendSignature,
211
+ sendError,
212
+ latestBlockhash,
213
+ } = useTransactionPool();
214
+
185
215
  return (
186
216
  <div>
187
- <button onClick={() => pool.addInstruction(ix)}>Add instruction</button>
188
- <button disabled={pool.isSending} onClick={() => pool.prepareAndSend()}>
189
- {pool.isSending ? "Sending…" : "Prepare & Send"}
217
+ <button onClick={() => addInstruction(ix)}>Add instruction</button>
218
+ <button
219
+ disabled={isSending || !session}
220
+ onClick={() => prepareAndSend({ authority: session })}
221
+ >
222
+ {isSending ? "Sending…" : "Prepare & Send"}
190
223
  </button>
191
- <p>Blockhash: {pool.latestBlockhash.blockhash ?? "loading…"}</p>
224
+ <p>Blockhash: {latestBlockhash.blockhash ?? "loading…"}</p>
225
+ {sendSignature ? <p>Signature: {sendSignature}</p> : null}
226
+ {sendError ? <p role="alert">{String(sendError)}</p> : null}
192
227
  </div>
193
228
  );
194
229
  }
195
230
  ```
196
231
 
232
+ **Available properties:**
233
+ - `addInstruction(ix)` / `addInstructions(ixs)` — queue instructions
234
+ - `removeInstruction(index)` / `clearInstructions()` / `replaceInstructions(ixs)` — manage queue
235
+ - `instructions` — current instruction queue
236
+ - `prepare(opts)` / `prepareAndSend(opts)` — build and optionally send
237
+ - `send(opts)` / `sign(opts)` — send or sign prepared transaction
238
+ - `isPreparing` / `prepareStatus` / `prepareError` — prepare state
239
+ - `isSending` / `sendStatus` / `sendError` / `sendSignature` — send state
240
+ - `latestBlockhash` — current blockhash for lifetime
241
+ - `prepared` / `toWire()` — access prepared transaction
242
+ - `reset()` — clear all state
243
+
197
244
  ### Simple mutation helper (when you already have instructions)
198
245
 
199
246
  ```tsx
200
247
  import { useSendTransaction } from "@solana/react-hooks";
201
248
 
202
249
  function SendPrepared({ instructions }) {
203
- const { send, isSending, signature, error } = useSendTransaction();
250
+ const { send, isSending, status, signature, error } = useSendTransaction();
204
251
  return (
205
252
  <div>
206
253
  <button disabled={isSending} onClick={() => send({ instructions })}>
207
254
  {isSending ? "Submitting…" : "Send transaction"}
208
255
  </button>
256
+ <p>Status: {status}</p>
209
257
  {signature ? <p>Signature: {signature}</p> : null}
210
258
  {error ? <p role="alert">{String(error)}</p> : null}
211
259
  </div>
@@ -213,6 +261,14 @@ function SendPrepared({ instructions }) {
213
261
  }
214
262
  ```
215
263
 
264
+ > **Note:** This hook automatically uses the connected wallet session — no need to pass `authority` explicitly.
265
+
266
+ **Available properties:**
267
+ - `send(request, opts?)` — build and send transaction
268
+ - `sendPrepared(prepared, opts?)` — send already-prepared transaction
269
+ - `isSending` / `status` / `signature` / `error` — transaction state
270
+ - `reset()` — clear state for new transaction
271
+
216
272
  ### Track confirmations for a signature
217
273
 
218
274
  ```tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/react-hooks",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "React hooks for the @solana/client Solana client",
5
5
  "exports": {
6
6
  "browser": "./dist/index.browser.mjs",