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
9 changes: 9 additions & 0 deletions .changeset/readme-fixes-113-115-108-110.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@solana/react-hooks": patch
---

Fix README documentation examples:
- Fix useSolTransfer: `lamports``amount` parameter
- Fix useSplToken: add `amountInBaseUnits: true` for bigint amounts
- Add `currentConnector` to useWalletConnection example
- Document useAccount hook with usage example
27 changes: 24 additions & 3 deletions packages/react-hooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ These snippets assume a parent already handled wallet connection and can pass an

```tsx
function WalletPanel() {
const { connectors, connect, disconnect, wallet, status } =
const { connectors, connect, disconnect, wallet, status, currentConnector } =
useWalletConnection();
const address = wallet?.account.address;
const balance = useBalance(address);

if (status === "connected") {
return (
<div>
<p>Connected via {currentConnector?.name}</p>
<p>{address?.toString()}</p>
<p>Lamports: {balance.lamports?.toString() ?? "loading…"}</p>
<button onClick={disconnect}>Disconnect</button>
Expand Down Expand Up @@ -85,6 +86,24 @@ function BalanceCard({ address }: { address: string }) {
}
```

### Read account data (auto fetch + watch)

```tsx
import { useAccount } from "@solana/react-hooks";

function AccountInfo({ address }: { address: string }) {
const account = useAccount(address);
if (!account || account.fetching) return <p>Loading…</p>;
return (
<div>
<p>Lamports: {account.lamports?.toString() ?? "0"}</p>
<p>Owner: {account.owner ?? "—"}</p>
<p>Slot: {account.slot?.toString() ?? "—"}</p>
</div>
);
}
```

### Send SOL

```tsx
Expand All @@ -97,7 +116,7 @@ function SendSol({ destination }: { destination: string }) {
<button
disabled={isSending}
onClick={() =>
send({ destination, lamports: 100_000_000n /* 0.1 SOL */ })
send({ destination, amount: 100_000_000n /* 0.1 SOL */ })
}
>
{isSending ? "Sending…" : "Send 0.1 SOL"}
Expand Down Expand Up @@ -129,7 +148,7 @@ function TokenPanel({
<p>Balance: {balance?.uiAmount ?? "0"}</p>
<button
disabled={isSending || !owner}
onClick={() => send({ amount: 1n, destinationOwner })}
onClick={() => send({ amount: 1n, destinationOwner, amountInBaseUnits: true })}
>
{isSending ? "Sending…" : "Send 1 token"}
</button>
Expand All @@ -138,6 +157,8 @@ function TokenPanel({
}
```

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

### Fetch address lookup tables

```tsx
Expand Down
Loading