@solana/react-hooks 1.1.9 → 1.1.11
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/README.md +24 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -46,7 +46,7 @@ These snippets assume a parent already handled wallet connection and can pass an
|
|
|
46
46
|
|
|
47
47
|
```tsx
|
|
48
48
|
function WalletPanel() {
|
|
49
|
-
const { connectors, connect, disconnect, wallet, status } =
|
|
49
|
+
const { connectors, connect, disconnect, wallet, status, currentConnector } =
|
|
50
50
|
useWalletConnection();
|
|
51
51
|
const address = wallet?.account.address;
|
|
52
52
|
const balance = useBalance(address);
|
|
@@ -54,6 +54,7 @@ function WalletPanel() {
|
|
|
54
54
|
if (status === "connected") {
|
|
55
55
|
return (
|
|
56
56
|
<div>
|
|
57
|
+
<p>Connected via {currentConnector?.name}</p>
|
|
57
58
|
<p>{address?.toString()}</p>
|
|
58
59
|
<p>Lamports: {balance.lamports?.toString() ?? "loading…"}</p>
|
|
59
60
|
<button onClick={disconnect}>Disconnect</button>
|
|
@@ -85,6 +86,24 @@ function BalanceCard({ address }: { address: string }) {
|
|
|
85
86
|
}
|
|
86
87
|
```
|
|
87
88
|
|
|
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
|
+
|
|
88
107
|
### Send SOL
|
|
89
108
|
|
|
90
109
|
```tsx
|
|
@@ -97,7 +116,7 @@ function SendSol({ destination }: { destination: string }) {
|
|
|
97
116
|
<button
|
|
98
117
|
disabled={isSending}
|
|
99
118
|
onClick={() =>
|
|
100
|
-
send({ destination,
|
|
119
|
+
send({ destination, amount: 100_000_000n /* 0.1 SOL */ })
|
|
101
120
|
}
|
|
102
121
|
>
|
|
103
122
|
{isSending ? "Sending…" : "Send 0.1 SOL"}
|
|
@@ -129,7 +148,7 @@ function TokenPanel({
|
|
|
129
148
|
<p>Balance: {balance?.uiAmount ?? "0"}</p>
|
|
130
149
|
<button
|
|
131
150
|
disabled={isSending || !owner}
|
|
132
|
-
onClick={() => send({ amount: 1n, destinationOwner })}
|
|
151
|
+
onClick={() => send({ amount: 1n, destinationOwner, amountInBaseUnits: true })}
|
|
133
152
|
>
|
|
134
153
|
{isSending ? "Sending…" : "Send 1 token"}
|
|
135
154
|
</button>
|
|
@@ -138,6 +157,8 @@ function TokenPanel({
|
|
|
138
157
|
}
|
|
139
158
|
```
|
|
140
159
|
|
|
160
|
+
> **Note:** Use `amountInBaseUnits: true` when passing raw bigint amounts. For human-readable decimal strings like `"1.5"`, omit the flag.
|
|
161
|
+
|
|
141
162
|
### Fetch address lookup tables
|
|
142
163
|
|
|
143
164
|
```tsx
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solana/react-hooks",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"description": "React hooks for the @solana/client Solana client",
|
|
5
5
|
"exports": {
|
|
6
6
|
"browser": "./dist/index.browser.mjs",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@solana/kit": "^5.0.0",
|
|
45
45
|
"swr": "^2.3.6",
|
|
46
46
|
"zustand": "^5.0.0",
|
|
47
|
-
"@solana/client": "1.
|
|
47
|
+
"@solana/client": "1.3.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/react": "^19.0.0",
|