Skip to content

Commit d2ca1ca

Browse files
authored
docs: fix README examples and add useAccount documentation (#128)
* docs: fix README examples and add useAccount documentation - Fix useSolTransfer: lamports → amount parameter (#113) - Fix useSplToken: add amountInBaseUnits for bigint (#115) - Add currentConnector to useWalletConnection example (#108) - Document useAccount hook with example (#110) * docs: add note explaining amountInBaseUnits parameter
1 parent db89c09 commit d2ca1ca

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@solana/react-hooks": patch
3+
---
4+
5+
Fix README documentation examples:
6+
- Fix useSolTransfer: `lamports``amount` parameter
7+
- Fix useSplToken: add `amountInBaseUnits: true` for bigint amounts
8+
- Add `currentConnector` to useWalletConnection example
9+
- Document useAccount hook with usage example

packages/react-hooks/README.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@ These snippets assume a parent already handled wallet connection and can pass an
4646

4747
```tsx
4848
function WalletPanel() {
49-
const { connectors, connect, disconnect, wallet, status } =
49+
const { connectors, connect, disconnect, wallet, status, currentConnector } =
5050
useWalletConnection();
5151
const address = wallet?.account.address;
5252
const balance = useBalance(address);
5353

5454
if (status === "connected") {
5555
return (
5656
<div>
57+
<p>Connected via {currentConnector?.name}</p>
5758
<p>{address?.toString()}</p>
5859
<p>Lamports: {balance.lamports?.toString() ?? "loading…"}</p>
5960
<button onClick={disconnect}>Disconnect</button>
@@ -85,6 +86,24 @@ function BalanceCard({ address }: { address: string }) {
8586
}
8687
```
8788

89+
### Read account data (auto fetch + watch)
90+
91+
```tsx
92+
import { useAccount } from "@solana/react-hooks";
93+
94+
function AccountInfo({ address }: { address: string }) {
95+
const account = useAccount(address);
96+
if (!account || account.fetching) return <p>Loading…</p>;
97+
return (
98+
<div>
99+
<p>Lamports: {account.lamports?.toString() ?? "0"}</p>
100+
<p>Owner: {account.owner ?? ""}</p>
101+
<p>Slot: {account.slot?.toString() ?? ""}</p>
102+
</div>
103+
);
104+
}
105+
```
106+
88107
### Send SOL
89108

90109
```tsx
@@ -97,7 +116,7 @@ function SendSol({ destination }: { destination: string }) {
97116
<button
98117
disabled={isSending}
99118
onClick={() =>
100-
send({ destination, lamports: 100_000_000n /* 0.1 SOL */ })
119+
send({ destination, amount: 100_000_000n /* 0.1 SOL */ })
101120
}
102121
>
103122
{isSending ? "Sending…" : "Send 0.1 SOL"}
@@ -129,7 +148,7 @@ function TokenPanel({
129148
<p>Balance: {balance?.uiAmount ?? "0"}</p>
130149
<button
131150
disabled={isSending || !owner}
132-
onClick={() => send({ amount: 1n, destinationOwner })}
151+
onClick={() => send({ amount: 1n, destinationOwner, amountInBaseUnits: true })}
133152
>
134153
{isSending ? "Sending…" : "Send 1 token"}
135154
</button>
@@ -138,6 +157,8 @@ function TokenPanel({
138157
}
139158
```
140159

160+
> **Note:** Use `amountInBaseUnits: true` when passing raw bigint amounts. For human-readable decimal strings like `"1.5"`, omit the flag.
161+
141162
### Fetch address lookup tables
142163

143164
```tsx

0 commit comments

Comments
 (0)