Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/usespltoken-readme-docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@solana/react-hooks': patch
---

Expand useSplToken README documentation with error handling example and complete property list
42 changes: 40 additions & 2 deletions packages/react-hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,62 @@ function TokenPanel({
mint: string;
destinationOwner: string;
}) {
const { balance, send, isSending, owner } = useSplToken(mint);
const {
balance,
send,
isSending,
owner,
status,
error,
sendError,
sendSignature,
resetSend,
} = useSplToken(mint);

if (status === "disconnected") return <p>Connect wallet to view balance</p>;
if (status === "loading") return <p>Loading balance…</p>;
if (status === "error") return <p role="alert">Error: {String(error)}</p>;

return (
<div>
<p>Owner: {owner ?? "Connect wallet"}</p>
<p>Owner: {owner}</p>
<p>Balance: {balance?.uiAmount ?? "0"}</p>
<button
disabled={isSending || !owner}
onClick={() => send({ amount: 1n, destinationOwner, amountInBaseUnits: true })}
>
{isSending ? "Sending…" : "Send 1 token"}
</button>
{sendSignature ? <p>Signature: {sendSignature}</p> : null}
{sendError ? (
<div>
<p role="alert">Send failed: {String(sendError)}</p>
<button onClick={resetSend}>Dismiss</button>
</div>
) : null}
</div>
);
}
```

> **Note:** Use `amountInBaseUnits: true` when passing raw bigint amounts. For human-readable decimal strings like `"1.5"`, omit the flag.

**Available properties:**
- `balance` / `owner` — token balance and owner address
- `status` — overall hook status ('disconnected' | 'error' | 'loading' | 'ready')
- `error` — error from balance fetching
- `send(config, opts?)` — transfer tokens to destination
- `isSending` / `sendStatus` / `sendError` / `sendSignature` — transfer state
- `refresh()` / `refreshing` — manually refresh balance
- `resetSend()` — clear send error state
- `helper` — low-level helper for advanced use

**Options (second parameter):**
- `commitment` — RPC commitment level
- `owner` — override balance owner (defaults to connected wallet)
- `revalidateOnFocus` — refresh when window regains focus
- `swr` — additional SWR options

### Fetch address lookup tables

```tsx
Expand Down
Loading