@solana/react-hooks 1.1.11 → 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.
- package/README.md +42 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -199,34 +199,61 @@ function NonceInfo({ address }: { address: string }) {
|
|
|
199
199
|
|
|
200
200
|
```tsx
|
|
201
201
|
import type { TransactionInstructionInput } from "@solana/client";
|
|
202
|
-
import { useTransactionPool } from "@solana/react-hooks";
|
|
202
|
+
import { useTransactionPool, useWalletSession } from "@solana/react-hooks";
|
|
203
203
|
|
|
204
204
|
function TransactionFlow({ ix }: { ix: TransactionInstructionInput }) {
|
|
205
|
-
const
|
|
205
|
+
const session = useWalletSession();
|
|
206
|
+
const {
|
|
207
|
+
addInstruction,
|
|
208
|
+
prepareAndSend,
|
|
209
|
+
isSending,
|
|
210
|
+
sendSignature,
|
|
211
|
+
sendError,
|
|
212
|
+
latestBlockhash,
|
|
213
|
+
} = useTransactionPool();
|
|
214
|
+
|
|
206
215
|
return (
|
|
207
216
|
<div>
|
|
208
|
-
<button onClick={() =>
|
|
209
|
-
<button
|
|
210
|
-
{
|
|
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"}
|
|
211
223
|
</button>
|
|
212
|
-
<p>Blockhash: {
|
|
224
|
+
<p>Blockhash: {latestBlockhash.blockhash ?? "loading…"}</p>
|
|
225
|
+
{sendSignature ? <p>Signature: {sendSignature}</p> : null}
|
|
226
|
+
{sendError ? <p role="alert">{String(sendError)}</p> : null}
|
|
213
227
|
</div>
|
|
214
228
|
);
|
|
215
229
|
}
|
|
216
230
|
```
|
|
217
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
|
+
|
|
218
244
|
### Simple mutation helper (when you already have instructions)
|
|
219
245
|
|
|
220
246
|
```tsx
|
|
221
247
|
import { useSendTransaction } from "@solana/react-hooks";
|
|
222
248
|
|
|
223
249
|
function SendPrepared({ instructions }) {
|
|
224
|
-
const { send, isSending, signature, error } = useSendTransaction();
|
|
250
|
+
const { send, isSending, status, signature, error } = useSendTransaction();
|
|
225
251
|
return (
|
|
226
252
|
<div>
|
|
227
253
|
<button disabled={isSending} onClick={() => send({ instructions })}>
|
|
228
254
|
{isSending ? "Submitting…" : "Send transaction"}
|
|
229
255
|
</button>
|
|
256
|
+
<p>Status: {status}</p>
|
|
230
257
|
{signature ? <p>Signature: {signature}</p> : null}
|
|
231
258
|
{error ? <p role="alert">{String(error)}</p> : null}
|
|
232
259
|
</div>
|
|
@@ -234,6 +261,14 @@ function SendPrepared({ instructions }) {
|
|
|
234
261
|
}
|
|
235
262
|
```
|
|
236
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
|
+
|
|
237
272
|
### Track confirmations for a signature
|
|
238
273
|
|
|
239
274
|
```tsx
|