You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: JSDoc all consumer-facing exports and update README (#59)
* docs: add JSDoc to all consumer-facing exports and update README
Add comprehensive JSDoc documentation to all hooks, errors, types,
utilities, provider, and constants. Update README with typed
useWriteContract examples, createContractConfig, error handling guide,
mutation return types table, and WalletConnect session management docs.
Closes#34
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: add link to @satoshai/abi-cli in typed useWriteContract section
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
* docs: correct SIP-030 compliance claim for Xverse and Leather
Neither wallet fully implements SIP-030. Xverse uses a proprietary
addListener('accountChange') API, and Leather does not emit account
change events at all.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
|`wallets`|`SupportedStacksWallet[]`| All 6 wallets | Wallets to enable. |
90
+
|`connectModal`|`boolean`|`true`| Show `@stacks/connect` modal on `connect()` with no args. |
91
+
|`walletConnect`|`{ projectId, metadata?, chains? }`| — | WalletConnect config. Required when `wallets` includes `'wallet-connect'`. |
92
+
|`onConnect`|`(provider, address) => void`| — | Called after successful connection. |
93
+
|`onAddressChange`|`(newAddress) => void`| — | Called when the connected account changes. |
94
+
|`onDisconnect`|`() => void`| — | Called when the wallet disconnects. |
95
+
85
96
> If `wallets` includes `'wallet-connect'`, you must provide `walletConnect.projectId` or the provider will throw at mount.
86
97
87
98
> **Important:** Define `wallets` and `walletConnect` outside of your component (or memoize them) so they remain referentially stable across renders. These values are treated as static configuration.
@@ -111,8 +122,10 @@ When `connectModal` is enabled:
111
122
112
123
### `useConnect()`
113
124
125
+
Connect to a Stacks wallet. Returns a mutation-style object.
disconnect(() => { /* callback after disconnect */ });
161
176
```
162
177
163
178
### `useAddress()`
164
179
180
+
Read the connected wallet's address and connection status. Returns a **discriminated union** — when `isConnected` is `true`, `address` and `provider` are narrowed to defined values (no null checks needed).
#### Typed mode (with ABI — autocomplete + type-checked args)
296
+
297
+
When you pass an `abi` object, `functionName` is autocompleted from the ABI's public functions and `args` becomes a named, type-checked object. Use [`@satoshai/abi-cli`](https://github.com/satoshai-dev/abi-cli) to generate typed ABIs from deployed contracts.
|`isIdle`|`boolean`|`true` when no operation has been triggered. |
402
+
|`isPending`|`boolean`|`true` while waiting for wallet response. |
403
+
|`isSuccess`|`boolean`|`true` after a successful operation. |
404
+
|`isError`|`boolean`|`true` after a failed operation. |
405
+
|`reset()`|`() => void`| Reset the mutation state back to idle. |
406
+
407
+
Each hook also provides both a **callback** variant (fire-and-forget with `onSuccess`/`onError`/`onSettled` callbacks) and an **async** variant that returns a promise.
408
+
409
+
## Error Handling
410
+
411
+
All errors thrown by hooks extend `BaseError`. You can catch and narrow them:
412
+
413
+
```ts
414
+
import {
415
+
BaseError,
416
+
WalletNotConnectedError,
417
+
WalletNotFoundError,
418
+
UnsupportedMethodError,
419
+
WalletRequestError,
420
+
} from'@satoshai/kit';
421
+
422
+
try {
423
+
awaitsignMessageAsync({ message: 'hello' });
424
+
} catch (err) {
425
+
if (errinstanceofWalletNotConnectedError) {
426
+
// No wallet connected — prompt user to connect
427
+
} elseif (errinstanceofUnsupportedMethodError) {
428
+
// Wallet doesn't support this method (e.g. OKX + structured signing)
429
+
console.log(err.method, err.wallet);
430
+
} elseif (errinstanceofWalletNotFoundError) {
431
+
// Wallet extension not installed
432
+
console.log(err.wallet);
433
+
} elseif (errinstanceofWalletRequestError) {
434
+
// Wallet rejected or failed — original error in cause
435
+
console.log(err.method, err.wallet, err.cause);
436
+
} elseif (errinstanceofBaseError) {
437
+
// Any other kit error
438
+
console.log(err.shortMessage);
439
+
console.log(err.walk()); // root cause
440
+
}
441
+
}
442
+
```
443
+
444
+
| Error | When |
445
+
|-------|------|
446
+
|`WalletNotConnectedError`| A mutation hook is called before connecting. |
447
+
|`WalletNotFoundError`| A wallet's browser extension is not installed (e.g. OKX). |
448
+
|`UnsupportedMethodError`| The wallet doesn't support the requested method. |
449
+
|`WalletRequestError`| The wallet rejected or failed the RPC request. |
450
+
451
+
## WalletConnect Session Management
452
+
453
+
When using WalletConnect, the kit automatically handles session lifecycle events:
454
+
455
+
-**Zombie session detection** — On app restore, the relay is pinged (10s timeout). If the wallet on the other end doesn't respond, the session is cleaned up and `onDisconnect` fires.
456
+
-**Wallet-initiated disconnect** — If the wallet disconnects via the relay, state is cleaned up automatically.
457
+
-**Account changes** — Listens for `accountsChanged`, `stx_accountChange` (SIP-030), and `stx_accountsChanged` events. When the connected account changes, `onAddressChange` fires.
458
+
459
+
No additional setup is needed — these features activate when `wallets` includes `'wallet-connect'` and a session is active.
460
+
307
461
## Supported Wallets
308
462
309
463
All 6 wallets work with both headless (`connect('xverse')`) and modal (`connect()`) modes.
@@ -328,15 +482,15 @@ All 6 wallets work with both headless (`connect('xverse')`) and modal (`connect(
328
482
|`useWriteContract`| ✓ | ✓ | ✓ | ✓ | ~ | ✓ |
329
483
|`useTransferSTX`| ✓ | ✓ | ✓ | ✓ | ~ | ✓ |
330
484
331
-
✓ Confirmed supported | ✗ Unsupported (throws error) | ? Unverified | ~ Depends on the connected wallet
485
+
✓ Confirmed supported | ✗ Unsupported (throws `UnsupportedMethodError`) | ? Unverified | ~ Depends on the connected wallet
332
486
333
487
**Notes:**
334
488
335
-
-**OKX** uses a proprietary API (`window.okxwallet.stacks`) instead of the standard `@stacks/connect` RPC. `useSignStructuredMessage` and `useSignTransaction` are explicitly unsupported and will throw.
489
+
-**OKX** uses a proprietary API (`window.okxwallet.stacks`) instead of the standard `@stacks/connect` RPC. `useSignStructuredMessage` and `useSignTransaction` are explicitly unsupported and will throw`UnsupportedMethodError`.
336
490
-**Asigna** is a multisig wallet. Transaction-based hooks (`useWriteContract`, `useTransferSTX`) work, but message signing hooks may be limited since there is no multisig message signature standard on Stacks.
337
491
-**Fordefi** supports transactions and contract calls on Stacks, but their [supported blockchains](https://docs.fordefi.com/docs/supported-blockchains) page does not list Stacks under message signing capabilities.
338
492
-**WalletConnect** is a relay protocol — all methods are forwarded, but actual support depends on the wallet on the other end.
339
-
-**Xverse** and **Leather**implement the full [SIP-030](https://github.com/janniks/sips/blob/main/sips/sip-030/sip-030-wallet-interface.md)interface.
493
+
-**Xverse** and **Leather**support all hooks provided by `@satoshai/kit`. Neither fully implements [SIP-030](https://github.com/janniks/sips/blob/main/sips/sip-030/sip-030-wallet-interface.md)— for example, account change detection uses Xverse's proprietary `XverseProviders.StacksProvider.addListener('accountChange')` API, and Leather does not emit account change events at all.
340
494
341
495
This matrix was compiled from wallet documentation as of March 2026. Sources: [Xverse Sats Connect docs](https://docs.xverse.app/sats-connect/stacks-methods), [Leather developer docs](https://leather.gitbook.io/developers), [Asigna docs](https://asigna.gitbook.io/asigna), [Fordefi docs](https://docs.fordefi.com/docs/supported-blockchains), [@stacks/connect WalletConnect source](https://github.com/stx-labs/connect/tree/main/packages/connect/src/walletconnect).
0 commit comments