@satoshai/kit 0.7.0 → 0.8.1

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/dist/index.d.ts CHANGED
@@ -3,53 +3,93 @@ import { ClarityValue, TupleCV, PostCondition, PostConditionMode } from '@stacks
3
3
  import { ClarityAbi, ExtractAbiFunctionNames, Pretty, ExtractAbiFunction, ClarityAbiArgToPrimitiveTypeValue } from 'clarity-abitype';
4
4
  export { ClarityAbi } from 'clarity-abitype';
5
5
 
6
+ /** Discriminated type for narrowing caught errors to `BaseError`. */
6
7
  type BaseErrorType = BaseError & {
7
8
  name: 'StacksKitError';
8
9
  };
10
+ /**
11
+ * Base error class for all `@satoshai/kit` errors.
12
+ *
13
+ * All errors thrown by hooks extend this class, so you can catch them with
14
+ * `error instanceof BaseError` and use {@link BaseError.walk | walk()} to
15
+ * traverse the cause chain.
16
+ *
17
+ * @example
18
+ * ```ts
19
+ * import { BaseError } from '@satoshai/kit';
20
+ *
21
+ * try {
22
+ * await signMessageAsync({ message: 'hello' });
23
+ * } catch (err) {
24
+ * if (err instanceof BaseError) {
25
+ * console.log(err.shortMessage); // human-readable summary
26
+ * console.log(err.walk()); // root cause
27
+ * }
28
+ * }
29
+ * ```
30
+ */
9
31
  declare class BaseError extends Error {
10
32
  name: string;
33
+ /** Short, human-readable error summary without details or cause chain. */
11
34
  shortMessage: string;
12
35
  constructor(shortMessage: string, options?: {
13
36
  cause?: Error;
14
37
  details?: string;
15
38
  });
39
+ /**
40
+ * Walk the error cause chain. If `fn` is provided, returns the first error
41
+ * where `fn` returns `true`; otherwise returns the root cause.
42
+ */
16
43
  walk(fn?: (err: unknown) => boolean): unknown;
17
44
  }
45
+ /** Discriminated type for narrowing to `WalletNotConnectedError`. */
18
46
  type WalletNotConnectedErrorType = WalletNotConnectedError & {
19
47
  name: 'WalletNotConnectedError';
20
48
  };
49
+ /** Thrown when a mutation hook is called before a wallet is connected. */
21
50
  declare class WalletNotConnectedError extends BaseError {
22
51
  name: string;
23
52
  constructor();
24
53
  }
54
+ /** Discriminated type for narrowing to `WalletNotFoundError`. */
25
55
  type WalletNotFoundErrorType = WalletNotFoundError & {
26
56
  name: 'WalletNotFoundError';
27
57
  };
58
+ /** Thrown when a wallet's browser extension is not installed (e.g. OKX). */
28
59
  declare class WalletNotFoundError extends BaseError {
29
60
  name: string;
61
+ /** The wallet ID that was not found. */
30
62
  wallet: string;
31
63
  constructor({ wallet }: {
32
64
  wallet: string;
33
65
  });
34
66
  }
67
+ /** Discriminated type for narrowing to `UnsupportedMethodError`. */
35
68
  type UnsupportedMethodErrorType = UnsupportedMethodError & {
36
69
  name: 'UnsupportedMethodError';
37
70
  };
71
+ /** Thrown when a wallet does not support the requested RPC method (e.g. OKX + `stx_signStructuredMessage`). */
38
72
  declare class UnsupportedMethodError extends BaseError {
39
73
  name: string;
74
+ /** The SIP-030 method name that is not supported. */
40
75
  method: string;
76
+ /** The wallet that does not support the method. */
41
77
  wallet: string;
42
78
  constructor({ method, wallet }: {
43
79
  method: string;
44
80
  wallet: string;
45
81
  });
46
82
  }
83
+ /** Discriminated type for narrowing to `WalletRequestError`. */
47
84
  type WalletRequestErrorType = WalletRequestError & {
48
85
  name: 'WalletRequestError';
49
86
  };
87
+ /** Thrown when a wallet RPC request fails (user rejection, timeout, etc.). The original error is attached as `cause`. */
50
88
  declare class WalletRequestError extends BaseError {
51
89
  name: string;
90
+ /** The SIP-030 method name that failed. */
52
91
  method: string;
92
+ /** The wallet that returned the error. */
53
93
  wallet: string;
54
94
  constructor({ method, wallet, cause }: {
55
95
  method: string;
@@ -58,35 +98,68 @@ declare class WalletRequestError extends BaseError {
58
98
  });
59
99
  }
60
100
 
101
+ /** All wallet IDs supported by `@satoshai/kit`. */
61
102
  declare const SUPPORTED_STACKS_WALLETS: readonly ["xverse", "leather", "asigna", "fordefi", "wallet-connect", "okx"];
103
+ /** Union of supported wallet identifiers. */
62
104
  type SupportedStacksWallet = (typeof SUPPORTED_STACKS_WALLETS)[number];
63
105
 
106
+ /** Stacks network identifier. */
64
107
  type StacksChain = 'mainnet' | 'testnet';
108
+ /** Status of a mutation hook (`useConnect`, `useSignMessage`, etc.). */
65
109
  type MutationStatus = 'idle' | 'pending' | 'error' | 'success';
110
+ /** Metadata passed to the WalletConnect relay for dApp identification. */
66
111
  interface WalletConnectMetadata {
67
112
  name: string;
68
113
  description: string;
69
114
  url: string;
70
115
  icons: string[];
71
116
  }
117
+ /** Optional callbacks for {@link useConnect}. */
72
118
  interface ConnectOptions {
119
+ /** Called with the connected address and wallet ID on success. */
73
120
  onSuccess?: (address: string, provider: SupportedStacksWallet) => void;
121
+ /** Called when the connection fails or is rejected. */
74
122
  onError?: (error: Error) => void;
75
123
  }
124
+ /** Props for the {@link StacksWalletProvider} component. */
76
125
  interface StacksWalletProviderProps {
77
126
  children: React.ReactNode;
127
+ /**
128
+ * Wallets to enable. Defaults to all supported wallets.
129
+ *
130
+ * **Tip:** Define this array outside your component or memoize it to keep
131
+ * the reference stable across renders.
132
+ */
78
133
  wallets?: SupportedStacksWallet[];
79
134
  /** Show @stacks/connect's built-in wallet selection modal when `connect()` is called without a `providerId`. Defaults to `true`. Set to `false` to manage wallet selection yourself (headless). */
80
135
  connectModal?: boolean;
136
+ /**
137
+ * WalletConnect configuration. Required when `wallets` includes `'wallet-connect'`.
138
+ *
139
+ * **Tip:** Define this object outside your component or memoize it to keep
140
+ * the reference stable across renders.
141
+ */
81
142
  walletConnect?: {
143
+ /** WalletConnect Cloud project ID from https://cloud.walletconnect.com. */
82
144
  projectId: string;
145
+ /** Override default dApp metadata shown in the wallet. */
83
146
  metadata?: Partial<WalletConnectMetadata>;
147
+ /** Stacks chains to request. Defaults to `['mainnet']`. */
84
148
  chains?: StacksChain[];
85
149
  };
150
+ /** Called after a wallet successfully connects. */
86
151
  onConnect?: (provider: SupportedStacksWallet, address: string) => void;
152
+ /** Called when the connected account changes (e.g. Xverse account switch, WalletConnect account change). */
87
153
  onAddressChange?: (newAddress: string) => void;
154
+ /** Called when the wallet disconnects (user-initiated or session expiry). */
88
155
  onDisconnect?: () => void;
89
156
  }
157
+ /**
158
+ * Discriminated union representing the wallet connection state.
159
+ *
160
+ * When `status` is `'connected'`, `address` and `provider` are guaranteed
161
+ * to be defined.
162
+ */
90
163
  type WalletState = {
91
164
  status: 'disconnected';
92
165
  address: undefined;
@@ -100,20 +173,54 @@ type WalletState = {
100
173
  address: string;
101
174
  provider: SupportedStacksWallet;
102
175
  };
176
+ /** Metadata for a single wallet returned by {@link useWallets}. */
103
177
  interface WalletInfo {
178
+ /** Wallet identifier used with `connect(id)`. */
104
179
  id: SupportedStacksWallet;
180
+ /** Human-readable wallet name. */
105
181
  name: string;
182
+ /** Wallet icon as a data URI. */
106
183
  icon: string;
184
+ /** URL to download/install the wallet extension. */
107
185
  webUrl: string;
186
+ /** `true` when the wallet extension is detected or WalletConnect is configured. */
108
187
  available: boolean;
109
188
  }
189
+ /** Full context value exposed by `StacksWalletProvider`. Extends {@link WalletState} with actions and wallet list. */
110
190
  type WalletContextValue = WalletState & {
191
+ /** Connect to a wallet. Pass a wallet ID to bypass the modal, or call with no args to show the `@stacks/connect` modal. */
111
192
  connect: (providerId?: SupportedStacksWallet, options?: ConnectOptions) => Promise<void>;
193
+ /** Disconnect the current wallet and clear persisted state. */
112
194
  disconnect: (callback?: () => void) => void;
195
+ /** Reset a stuck connecting state back to idle. */
113
196
  reset: () => void;
197
+ /** All configured wallets with availability status. */
114
198
  wallets: WalletInfo[];
115
199
  };
116
200
 
201
+ /**
202
+ * React context provider that manages wallet connection state for all `@satoshai/kit` hooks.
203
+ *
204
+ * Wrap your app (or the subtree that needs wallet access) with this provider.
205
+ * All hooks (`useConnect`, `useAddress`, `useWriteContract`, etc.) must be
206
+ * rendered inside this provider.
207
+ *
208
+ * @example
209
+ * ```tsx
210
+ * import { StacksWalletProvider } from '@satoshai/kit';
211
+ *
212
+ * const wallets = ['xverse', 'leather', 'wallet-connect'] as const;
213
+ * const wc = { projectId: 'YOUR_PROJECT_ID' };
214
+ *
215
+ * function App() {
216
+ * return (
217
+ * <StacksWalletProvider wallets={[...wallets]} walletConnect={wc}>
218
+ * <YourApp />
219
+ * </StacksWalletProvider>
220
+ * );
221
+ * }
222
+ * ```
223
+ */
117
224
  declare const StacksWalletProvider: ({ children, wallets, connectModal, walletConnect, onConnect, onAddressChange, onDisconnect, }: StacksWalletProviderProps) => react_jsx_runtime.JSX.Element;
118
225
 
119
226
  type UseAddressReturn = {
@@ -129,8 +236,48 @@ type UseAddressReturn = {
129
236
  isDisconnected: false;
130
237
  provider: SupportedStacksWallet;
131
238
  };
239
+ /**
240
+ * Read the connected wallet's address and connection status.
241
+ *
242
+ * Returns a discriminated union — when `isConnected` is `true`, `address`
243
+ * and `provider` are guaranteed to be defined (no null checks needed).
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * const { address, isConnected, provider } = useAddress();
248
+ *
249
+ * if (isConnected) {
250
+ * console.log(address); // 'SP...' — narrowed to string
251
+ * console.log(provider); // 'xverse' | 'leather' | ...
252
+ * }
253
+ * ```
254
+ */
132
255
  declare const useAddress: () => UseAddressReturn;
133
256
 
257
+ /**
258
+ * Connect to a Stacks wallet.
259
+ *
260
+ * Returns a mutation-style object with `connect`, `reset`, and status flags.
261
+ * Call `connect()` with no args to open the `@stacks/connect` wallet modal,
262
+ * or pass a specific wallet ID (e.g. `connect('xverse')`) to connect directly.
263
+ *
264
+ * @example
265
+ * ```ts
266
+ * const { connect, reset, isPending, isSuccess, error } = useConnect();
267
+ *
268
+ * // Modal mode (default)
269
+ * await connect();
270
+ *
271
+ * // Direct mode
272
+ * await connect('leather', {
273
+ * onSuccess: (address, provider) => console.log(address),
274
+ * onError: (err) => console.error(err),
275
+ * });
276
+ *
277
+ * // Cancel a stuck connection (e.g. OKX popup dismissed)
278
+ * reset();
279
+ * ```
280
+ */
134
281
  declare const useConnect: () => {
135
282
  connect: (providerId?: SupportedStacksWallet, options?: ConnectOptions) => Promise<void>;
136
283
  reset: () => void;
@@ -142,6 +289,20 @@ declare const useConnect: () => {
142
289
  status: MutationStatus;
143
290
  };
144
291
 
292
+ /**
293
+ * Disconnect the currently connected wallet.
294
+ *
295
+ * Clears wallet state, removes the persisted session from localStorage,
296
+ * and resets the provider context back to `disconnected`.
297
+ *
298
+ * @example
299
+ * ```ts
300
+ * const { disconnect, isSuccess } = useDisconnect();
301
+ *
302
+ * disconnect();
303
+ * disconnect(() => navigate('/'));
304
+ * ```
305
+ */
145
306
  declare const useDisconnect: () => {
146
307
  disconnect: (callback?: () => void) => void;
147
308
  reset: () => void;
@@ -153,19 +314,45 @@ declare const useDisconnect: () => {
153
314
  status: MutationStatus;
154
315
  };
155
316
 
317
+ /** Variables for {@link useSignMessage}. */
156
318
  interface SignMessageVariables {
319
+ /** The plaintext message to sign. */
157
320
  message: string;
321
+ /** Optional public key hint for wallets that manage multiple keys. */
158
322
  publicKey?: string;
159
323
  }
324
+ /** Successful result from {@link useSignMessage}. */
160
325
  interface SignMessageData {
326
+ /** The public key that produced the signature. */
161
327
  publicKey: string;
328
+ /** The hex-encoded signature. */
162
329
  signature: string;
163
330
  }
331
+ /** Callback options for the fire-and-forget `signMessage()` variant. */
164
332
  interface SignMessageOptions {
165
333
  onSuccess?: (data: SignMessageData) => void;
166
334
  onError?: (error: Error) => void;
167
335
  onSettled?: (data: SignMessageData | undefined, error: Error | null) => void;
168
336
  }
337
+ /**
338
+ * Sign an arbitrary plaintext message with the connected wallet.
339
+ *
340
+ * Provides both a callback-style `signMessage()` and a promise-based
341
+ * `signMessageAsync()`, plus mutation status flags.
342
+ *
343
+ * @example
344
+ * ```ts
345
+ * const { signMessageAsync, isPending } = useSignMessage();
346
+ *
347
+ * const { publicKey, signature } = await signMessageAsync({
348
+ * message: 'Hello Stacks',
349
+ * });
350
+ * ```
351
+ *
352
+ * @throws {WalletNotConnectedError} If no wallet is connected.
353
+ * @throws {WalletNotFoundError} If OKX extension is not installed.
354
+ * @throws {WalletRequestError} If the wallet rejects or fails the request.
355
+ */
169
356
  declare const useSignMessage: () => {
170
357
  signMessage: (variables: SignMessageVariables, options?: SignMessageOptions) => void;
171
358
  signMessageAsync: (variables: SignMessageVariables) => Promise<SignMessageData>;
@@ -179,19 +366,46 @@ declare const useSignMessage: () => {
179
366
  status: MutationStatus;
180
367
  };
181
368
 
369
+ /** Variables for {@link useSignStructuredMessage}. */
182
370
  interface SignStructuredMessageVariables {
371
+ /** The structured Clarity value to sign. */
183
372
  message: ClarityValue;
373
+ /** SIP-018 domain tuple (name, version, chain-id). */
184
374
  domain: TupleCV;
185
375
  }
376
+ /** Successful result from {@link useSignStructuredMessage}. */
186
377
  interface SignStructuredMessageData {
187
378
  publicKey: string;
188
379
  signature: string;
189
380
  }
381
+ /** Callback options for the fire-and-forget `signStructuredMessage()` variant. */
190
382
  interface SignStructuredMessageOptions {
191
383
  onSuccess?: (data: SignStructuredMessageData) => void;
192
384
  onError?: (error: Error) => void;
193
385
  onSettled?: (data: SignStructuredMessageData | undefined, error: Error | null) => void;
194
386
  }
387
+ /**
388
+ * Sign SIP-018 structured data with the connected wallet.
389
+ *
390
+ * Structured messages include a typed domain separator and a Clarity value
391
+ * body, enabling verifiable off-chain signatures that are replay-safe.
392
+ *
393
+ * @example
394
+ * ```ts
395
+ * import { tupleCV, stringAsciiCV, uintCV } from '@stacks/transactions';
396
+ *
397
+ * const { signStructuredMessageAsync } = useSignStructuredMessage();
398
+ *
399
+ * const { signature } = await signStructuredMessageAsync({
400
+ * domain: tupleCV({ name: stringAsciiCV('MyApp'), version: stringAsciiCV('1.0'), 'chain-id': uintCV(1) }),
401
+ * message: tupleCV({ action: stringAsciiCV('authorize') }),
402
+ * });
403
+ * ```
404
+ *
405
+ * @throws {WalletNotConnectedError} If no wallet is connected.
406
+ * @throws {UnsupportedMethodError} If the wallet does not support structured signing (OKX).
407
+ * @throws {WalletRequestError} If the wallet rejects or fails the request.
408
+ */
195
409
  declare const useSignStructuredMessage: () => {
196
410
  signStructuredMessage: (variables: SignStructuredMessageVariables, options?: SignStructuredMessageOptions) => void;
197
411
  signStructuredMessageAsync: (variables: SignStructuredMessageVariables) => Promise<SignStructuredMessageData>;
@@ -205,19 +419,46 @@ declare const useSignStructuredMessage: () => {
205
419
  status: MutationStatus;
206
420
  };
207
421
 
422
+ /** Variables for {@link useSignTransaction}. */
208
423
  interface SignTransactionVariables {
424
+ /** Hex-encoded serialized transaction to sign. */
209
425
  transaction: string;
426
+ /** Whether to broadcast the signed transaction. Defaults to the wallet's behavior. */
210
427
  broadcast?: boolean;
211
428
  }
429
+ /** Successful result from {@link useSignTransaction}. */
212
430
  interface SignTransactionData {
431
+ /** The signed, hex-encoded transaction. */
213
432
  transaction: string;
433
+ /** Transaction ID, present when the wallet broadcasts it. */
214
434
  txid?: string;
215
435
  }
436
+ /** Callback options for the fire-and-forget `signTransaction()` variant. */
216
437
  interface SignTransactionOptions {
217
438
  onSuccess?: (data: SignTransactionData) => void;
218
439
  onError?: (error: Error) => void;
219
440
  onSettled?: (data: SignTransactionData | undefined, error: Error | null) => void;
220
441
  }
442
+ /**
443
+ * Sign a serialized Stacks transaction without automatic broadcast.
444
+ *
445
+ * Useful for sponsored transaction flows where a separate service pays the
446
+ * fee and broadcasts the transaction.
447
+ *
448
+ * @example
449
+ * ```ts
450
+ * const { signTransactionAsync } = useSignTransaction();
451
+ *
452
+ * const { transaction } = await signTransactionAsync({
453
+ * transaction: '0x0100...',
454
+ * broadcast: false,
455
+ * });
456
+ * ```
457
+ *
458
+ * @throws {WalletNotConnectedError} If no wallet is connected.
459
+ * @throws {UnsupportedMethodError} If the wallet does not support raw signing (OKX).
460
+ * @throws {WalletRequestError} If the wallet rejects or fails the request.
461
+ */
221
462
  declare const useSignTransaction: () => {
222
463
  signTransaction: (variables: SignTransactionVariables, options?: SignTransactionOptions) => void;
223
464
  signTransactionAsync: (variables: SignTransactionVariables) => Promise<SignTransactionData>;
@@ -231,18 +472,46 @@ declare const useSignTransaction: () => {
231
472
  status: MutationStatus;
232
473
  };
233
474
 
475
+ /** Variables for {@link useTransferSTX}. */
234
476
  interface TransferSTXVariables {
477
+ /** Recipient Stacks address (`SP...` or `ST...`). */
235
478
  recipient: string;
479
+ /** Amount in microSTX. Accepts `bigint`, `number`, or numeric `string`. */
236
480
  amount: bigint | number | string;
481
+ /** Optional memo string attached to the transfer. */
237
482
  memo?: string;
483
+ /** Custom fee in microSTX. Omit to let the wallet estimate. */
238
484
  fee?: bigint | number | string;
485
+ /** Custom nonce. Omit to let the wallet manage. */
239
486
  nonce?: bigint | number | string;
240
487
  }
488
+ /** Callback options for the fire-and-forget `transferSTX()` variant. */
241
489
  interface TransferSTXOptions {
242
490
  onSuccess?: (txid: string) => void;
243
491
  onError?: (error: Error) => void;
244
492
  onSettled?: (txid: string | undefined, error: Error | null) => void;
245
493
  }
494
+ /**
495
+ * Transfer native STX tokens to a recipient address.
496
+ *
497
+ * Returns the broadcast transaction ID on success. Supports all 6 wallets
498
+ * (OKX uses its proprietary API internally).
499
+ *
500
+ * @example
501
+ * ```ts
502
+ * const { transferSTXAsync, isPending } = useTransferSTX();
503
+ *
504
+ * const txid = await transferSTXAsync({
505
+ * recipient: 'SP2...',
506
+ * amount: 1_000_000n, // 1 STX
507
+ * memo: 'coffee',
508
+ * });
509
+ * ```
510
+ *
511
+ * @throws {WalletNotConnectedError} If no wallet is connected.
512
+ * @throws {WalletNotFoundError} If OKX extension is not installed.
513
+ * @throws {WalletRequestError} If the wallet rejects or fails the request.
514
+ */
246
515
  declare const useTransferSTX: () => {
247
516
  transferSTX: (variables: TransferSTXVariables, options?: TransferSTXOptions) => void;
248
517
  transferSTXAsync: (variables: TransferSTXVariables) => Promise<string>;
@@ -265,8 +534,11 @@ type PublicFunctionArgs<TAbi extends ClarityAbi, TFn extends ExtractAbiFunctionN
265
534
  [K in ExtractAbiFunction<TAbi, TFn, 'public'>['args'][number] as K['name']]: ClarityAbiArgToPrimitiveTypeValue<K>;
266
535
  }>;
267
536
 
537
+ /** Post-condition configuration for contract calls and STX transfers. */
268
538
  interface PostConditionConfig {
539
+ /** Array of post-conditions that must be satisfied for the transaction to succeed. */
269
540
  postConditions: PostCondition[];
541
+ /** Whether to allow or deny any asset transfers not covered by `postConditions`. */
270
542
  mode: PostConditionMode;
271
543
  }
272
544
  /** Typed mode: ABI present, args is a named object with autocomplete. */
@@ -288,6 +560,7 @@ interface UntypedWriteContractVariables {
288
560
  }
289
561
  /** Backward-compatible alias for the untyped variant. */
290
562
  type WriteContractVariables = UntypedWriteContractVariables;
563
+ /** Callback options for the fire-and-forget `writeContract()` variant. */
291
564
  interface WriteContractOptions {
292
565
  onSuccess?: (txHash: string) => void;
293
566
  onError?: (error: Error) => void;
@@ -304,6 +577,46 @@ interface WriteContractFn {
304
577
  (variables: UntypedWriteContractVariables, options?: WriteContractOptions): void;
305
578
  }
306
579
 
580
+ /**
581
+ * Call a public function on a Clarity smart contract.
582
+ *
583
+ * Supports two modes:
584
+ * - **Typed** (with ABI) — pass an ABI object for autocomplete on `functionName` and `args`.
585
+ * - **Untyped** — pass `ClarityValue[]` directly as `args`.
586
+ *
587
+ * @example
588
+ * ```ts
589
+ * import { Pc, PostConditionMode } from '@stacks/transactions';
590
+ *
591
+ * const { writeContractAsync } = useWriteContract();
592
+ *
593
+ * // Untyped mode
594
+ * const txid = await writeContractAsync({
595
+ * address: 'SP...',
596
+ * contract: 'my-contract',
597
+ * functionName: 'transfer',
598
+ * args: [uintCV(100)],
599
+ * pc: {
600
+ * postConditions: [Pc.principal('SP...').willSendLte(100n).ustx()],
601
+ * mode: PostConditionMode.Deny,
602
+ * },
603
+ * });
604
+ *
605
+ * // Typed mode (with ABI — enables autocomplete)
606
+ * const txid = await writeContractAsync({
607
+ * abi: myContractAbi,
608
+ * address: 'SP...',
609
+ * contract: 'my-contract',
610
+ * functionName: 'transfer', // autocompleted from ABI
611
+ * args: { amount: 100n }, // named args, type-checked
612
+ * pc: { postConditions: [], mode: PostConditionMode.Deny },
613
+ * });
614
+ * ```
615
+ *
616
+ * @throws {WalletNotConnectedError} If no wallet is connected.
617
+ * @throws {WalletNotFoundError} If OKX extension is not installed.
618
+ * @throws {WalletRequestError} If the wallet rejects or fails the request.
619
+ */
307
620
  declare const useWriteContract: () => {
308
621
  writeContract: WriteContractFn;
309
622
  writeContractAsync: WriteContractAsyncFn;
@@ -317,29 +630,100 @@ declare const useWriteContract: () => {
317
630
  status: MutationStatus;
318
631
  };
319
632
 
633
+ /**
634
+ * Resolve a BNS v2 primary name for a Stacks address.
635
+ *
636
+ * Returns `null` when no name is registered or the address is undefined.
637
+ * Automatically detects mainnet/testnet from the address prefix.
638
+ *
639
+ * @param address - Stacks address to resolve (`SP...` or `ST...`).
640
+ *
641
+ * @example
642
+ * ```ts
643
+ * const { bnsName, isLoading } = useBnsName('SP2...');
644
+ * // bnsName = 'satoshi.btc' | null
645
+ * ```
646
+ */
320
647
  declare const useBnsName: (address?: string) => {
321
648
  bnsName: string | null;
322
649
  isLoading: boolean;
323
650
  };
324
651
 
652
+ /**
653
+ * List all configured wallets with availability status.
654
+ *
655
+ * Each wallet includes its `id`, display `name`, `icon` (data URI), `webUrl`
656
+ * (install link), and whether it's `available` (extension detected or
657
+ * WalletConnect configured).
658
+ *
659
+ * @example
660
+ * ```ts
661
+ * const { wallets } = useWallets();
662
+ *
663
+ * wallets.map(({ id, name, icon, available }) => (
664
+ * <button key={id} onClick={() => connect(id)} disabled={!available}>
665
+ * <img src={icon} alt={name} width={20} /> {name}
666
+ * </button>
667
+ * ));
668
+ * ```
669
+ */
325
670
  declare const useWallets: () => {
326
671
  wallets: WalletInfo[];
327
672
  };
328
673
 
674
+ /**
675
+ * Infer the Stacks network from an address prefix.
676
+ *
677
+ * @param address - A Stacks address starting with `SP`/`SM` (mainnet) or `ST`/`SN` (testnet).
678
+ * @returns `'mainnet'` or `'testnet'`.
679
+ * @throws If the address doesn't start with a known prefix.
680
+ */
329
681
  declare const getNetworkFromAddress: (address: string) => "mainnet" | "testnet";
330
682
 
683
+ /**
684
+ * Read the persisted wallet session from localStorage.
685
+ *
686
+ * Returns `null` on the server, when no session is stored, or when the
687
+ * stored provider is not in the supported wallets list.
688
+ */
331
689
  declare const getLocalStorageWallet: () => {
332
690
  address: string;
333
691
  provider: SupportedStacksWallet;
334
692
  } | null;
335
693
 
694
+ /** Result of {@link getStacksWallets}. */
336
695
  interface StacksWallets {
696
+ /** All wallets supported by `@satoshai/kit`. */
337
697
  supported: SupportedStacksWallet[];
698
+ /** Subset of `supported` whose browser extension is currently detected. */
338
699
  installed: SupportedStacksWallet[];
339
700
  }
701
+ /**
702
+ * Detect which Stacks wallets are supported and installed.
703
+ *
704
+ * Safe to call on the server — `installed` will contain only `'wallet-connect'`
705
+ * when `window` is undefined.
706
+ */
340
707
  declare const getStacksWallets: () => StacksWallets;
341
708
 
342
- /** Pre-bind ABI + address + contract for reuse with useWriteContract. */
709
+ /**
710
+ * Pre-bind ABI, address, and contract name for reuse with `useWriteContract`.
711
+ *
712
+ * Returns the config object as-is but preserves the `const` ABI type, enabling
713
+ * autocomplete on `functionName` and type-checked `args` when spread into
714
+ * `writeContract()`.
715
+ *
716
+ * @example
717
+ * ```ts
718
+ * const pool = createContractConfig({
719
+ * abi: poolAbi,
720
+ * address: 'SP...',
721
+ * contract: 'pool-v1',
722
+ * });
723
+ *
724
+ * writeContract({ ...pool, functionName: 'deposit', args: { amount: 100n }, pc });
725
+ * ```
726
+ */
343
727
  declare function createContractConfig<const TAbi extends ClarityAbi>(config: {
344
728
  abi: TAbi;
345
729
  address: string;