@solana/client 1.0.0 → 1.1.0
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 +150 -38
- package/dist/index.browser.cjs +668 -64
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.mjs +666 -67
- package/dist/index.browser.mjs.map +1 -1
- package/dist/index.native.mjs +666 -67
- package/dist/index.native.mjs.map +1 -1
- package/dist/index.node.cjs +668 -64
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +666 -67
- package/dist/index.node.mjs.map +1 -1
- package/dist/types/actions.d.ts +22 -1
- package/dist/types/actions.d.ts.map +1 -1
- package/dist/types/client/actions.d.ts.map +1 -1
- package/dist/types/client/createClient.d.ts.map +1 -1
- package/dist/types/client/createClientHelpers.d.ts.map +1 -1
- package/dist/types/controllers/stakeController.d.ts +37 -0
- package/dist/types/controllers/stakeController.d.ts.map +1 -0
- package/dist/types/features/stake.d.ts +115 -0
- package/dist/types/features/stake.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +35 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/wallet/standard.d.ts.map +1 -1
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -8,79 +8,191 @@ in any runtime (React, Svelte, API routes, workers, etc.).
|
|
|
8
8
|
## Install
|
|
9
9
|
|
|
10
10
|
```bash
|
|
11
|
-
|
|
11
|
+
npm install @solana/client
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
##
|
|
14
|
+
## Quickstart
|
|
15
|
+
|
|
16
|
+
1. Choose Wallet Standard connectors (auto-discovery is the fastest way to start).
|
|
17
|
+
2. Create a Solana client.
|
|
18
|
+
3. Call actions, watchers, and helpers anywhere in your app (React, APIs, workers, etc.).
|
|
15
19
|
|
|
16
20
|
```ts
|
|
17
|
-
import { autoDiscover,
|
|
21
|
+
import { autoDiscover, createClient } from "@solana/client";
|
|
18
22
|
|
|
19
|
-
const walletConnectors = [...phantom(), ...solflare(), ...backpack(), ...autoDiscover()];
|
|
20
23
|
const client = createClient({
|
|
21
24
|
endpoint: "https://api.devnet.solana.com",
|
|
22
25
|
websocketEndpoint: "wss://api.devnet.solana.com",
|
|
23
|
-
walletConnectors,
|
|
26
|
+
walletConnectors: autoDiscover(),
|
|
24
27
|
});
|
|
25
28
|
|
|
26
29
|
// Connect Wallet Standard apps via their connector ids.
|
|
27
30
|
await client.actions.connectWallet("phantom");
|
|
28
31
|
|
|
29
32
|
// Fetch an account once.
|
|
30
|
-
const
|
|
31
|
-
|
|
33
|
+
const wallet = client.store.getState().wallet;
|
|
34
|
+
if (wallet.status === "connected") {
|
|
35
|
+
const account = await client.actions.fetchAccount(wallet.session.account.address);
|
|
36
|
+
console.log(account.lamports?.toString());
|
|
37
|
+
}
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Common Solana flows (copy/paste)
|
|
41
|
+
|
|
42
|
+
### Connect, disconnect, and inspect wallet state
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
const connectors = client.connectors.all; // Wallet Standard-aware connectors
|
|
46
|
+
|
|
47
|
+
await client.actions.connectWallet(connectors[0].id);
|
|
48
|
+
|
|
49
|
+
const wallet = client.store.getState().wallet;
|
|
50
|
+
if (wallet.status === "connected") {
|
|
51
|
+
console.log(wallet.session.account.address.toString());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
await client.actions.disconnectWallet();
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Fetch and watch lamports
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { toAddress } from "@solana/client";
|
|
32
61
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
62
|
+
const address = toAddress("Fg6PaFpoGXkYsidMpWFKfwtz6DhFVyG4dL1x8kj7ZJup");
|
|
63
|
+
|
|
64
|
+
const lamports = await client.actions.fetchBalance(address);
|
|
65
|
+
console.log(`Lamports: ${lamports.toString()}`);
|
|
66
|
+
|
|
67
|
+
const watcher = client.watchers.watchBalance({ address }, (nextLamports) => {
|
|
68
|
+
console.log("Updated balance:", nextLamports.toString());
|
|
36
69
|
});
|
|
37
70
|
|
|
38
71
|
// Later…
|
|
39
72
|
watcher.abort();
|
|
40
73
|
```
|
|
41
74
|
|
|
42
|
-
|
|
75
|
+
### Request an airdrop (devnet/testnet)
|
|
43
76
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
updates into the store and call your listeners.
|
|
49
|
-
- **Helpers** – Opinionated utilities for SOL transfers, SPL tokens, and transactions. They handle
|
|
50
|
-
mundane tasks like resolving fee payers, refreshing blockhashes, or signing with Wallet Standard
|
|
51
|
-
sessions.
|
|
77
|
+
```ts
|
|
78
|
+
const signature = await client.actions.requestAirdrop(address, 1_000_000_000n); // 1 SOL
|
|
79
|
+
console.log(signature.toString());
|
|
80
|
+
```
|
|
52
81
|
|
|
53
|
-
|
|
82
|
+
### Send SOL
|
|
54
83
|
|
|
55
|
-
|
|
84
|
+
```ts
|
|
85
|
+
const wallet = client.store.getState().wallet;
|
|
86
|
+
if (wallet.status !== "connected") throw new Error("Connect wallet first");
|
|
87
|
+
|
|
88
|
+
const signature = await client.solTransfer.sendTransfer({
|
|
89
|
+
amount: 100_000_000n, // 0.1 SOL
|
|
90
|
+
authority: wallet.session, // Wallet Standard session
|
|
91
|
+
destination: "Ff34MXWdgNsEJ1kJFj9cXmrEe7y2P93b95mGu5CJjBQJ",
|
|
92
|
+
});
|
|
93
|
+
console.log(signature.toString());
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### SPL token balance + transfer
|
|
56
97
|
|
|
57
98
|
```ts
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
99
|
+
const wallet = client.store.getState().wallet;
|
|
100
|
+
if (wallet.status !== "connected") throw new Error("Connect wallet first");
|
|
101
|
+
|
|
102
|
+
const usdc = client.splToken({ mint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v" }); // USDC
|
|
103
|
+
|
|
104
|
+
const balance = await usdc.fetchBalance(wallet.session.account.address);
|
|
105
|
+
console.log(`Balance: ${balance.uiAmount}`);
|
|
106
|
+
|
|
107
|
+
const signature = await usdc.sendTransfer({
|
|
108
|
+
amount: 1n,
|
|
109
|
+
authority: wallet.session,
|
|
110
|
+
destinationOwner: "Ff34MXWdgNsEJ1kJFj9cXmrEe7y2P93b95mGu5CJjBQJ",
|
|
61
111
|
});
|
|
112
|
+
console.log(signature.toString());
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Fetch address lookup tables
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
import { toAddress } from "@solana/client";
|
|
119
|
+
|
|
120
|
+
// Single lookup table
|
|
121
|
+
const lut = await client.actions.fetchLookupTable(
|
|
122
|
+
toAddress("AddressLookupTab1e1111111111111111111111111"),
|
|
123
|
+
);
|
|
124
|
+
console.log(`Addresses in LUT: ${lut.addresses.length}`);
|
|
125
|
+
|
|
126
|
+
// Multiple lookup tables
|
|
127
|
+
const luts = await client.actions.fetchLookupTables([lutAddress1, lutAddress2]);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Fetch nonce accounts
|
|
131
|
+
|
|
132
|
+
```ts
|
|
133
|
+
const nonce = await client.actions.fetchNonceAccount(
|
|
134
|
+
toAddress("NonceAccountAddress111111111111111111111111"),
|
|
135
|
+
);
|
|
136
|
+
console.log(`Nonce: ${nonce.blockhash}`);
|
|
137
|
+
console.log(`Authority: ${nonce.authority}`);
|
|
138
|
+
```
|
|
62
139
|
|
|
63
|
-
|
|
140
|
+
### Build and send arbitrary transactions
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
import { getTransferSolInstruction } from "@solana-program/system";
|
|
144
|
+
|
|
145
|
+
const wallet = client.store.getState().wallet;
|
|
146
|
+
if (wallet.status !== "connected") throw new Error("Connect wallet first");
|
|
147
|
+
|
|
148
|
+
const prepared = await client.transaction.prepare({
|
|
149
|
+
authority: wallet.session,
|
|
150
|
+
instructions: [
|
|
151
|
+
getTransferSolInstruction({
|
|
152
|
+
destination: "Ff34MXWdgNsEJ1kJFj9cXmrEe7y2P93b95mGu5CJjBQJ",
|
|
153
|
+
lamports: 10_000n,
|
|
154
|
+
source: wallet.session.account.address,
|
|
155
|
+
}),
|
|
156
|
+
],
|
|
157
|
+
version: "auto", // defaults to 0 when lookups exist, otherwise 'legacy'
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// Inspect or serialize first.
|
|
161
|
+
const wire = await client.transaction.toWire(prepared);
|
|
162
|
+
|
|
163
|
+
// Submit.
|
|
164
|
+
const signature = await client.transaction.send(prepared);
|
|
64
165
|
console.log(signature.toString());
|
|
65
166
|
```
|
|
66
167
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
168
|
+
### Watch signature confirmations
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
const watcher = client.watchers.watchSignature(
|
|
172
|
+
{ signature, commitment: "confirmed" },
|
|
173
|
+
(notification) => console.log("Signature update:", notification),
|
|
174
|
+
);
|
|
72
175
|
|
|
73
|
-
|
|
176
|
+
// Later…
|
|
177
|
+
watcher.abort();
|
|
178
|
+
```
|
|
74
179
|
|
|
75
|
-
##
|
|
180
|
+
## Notes and defaults
|
|
76
181
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
`
|
|
80
|
-
|
|
182
|
+
- Wallet connectors: `autoDiscover()` picks up Wallet Standard injectables; compose `phantom()`, `solflare()`, `backpack()`, or `injected()` when you need explicit control.
|
|
183
|
+
- Store: built on Zustand; pass `createStore` to `createClient` for custom persistence or server-side stores. `serializeSolanaState` / `deserializeSolanaState` help save and restore cluster + wallet metadata.
|
|
184
|
+
- Actions: `fetchAccount`, `fetchBalance`, `fetchLookupTable`, `fetchLookupTables`, `fetchNonceAccount`, `setCluster`, `requestAirdrop`, `sendTransaction`, and wallet connect/disconnect keep the store in sync.
|
|
185
|
+
- Watchers: `watchAccount`, `watchBalance`, and `watchSignature` stream updates into the store and return an `abort()` handle for cleanup.
|
|
186
|
+
- Helpers: `solTransfer`, `splToken`, and `transaction` cover common transfers plus low-level `prepare`/`sign`/`toWire` flows. Transaction versions default to `0` when any instruction references address lookup tables, otherwise `legacy`; override with `version` when needed.
|
|
81
187
|
|
|
82
188
|
## Scripts
|
|
83
189
|
|
|
84
|
-
- `pnpm build` –
|
|
85
|
-
- `pnpm test:typecheck` – strict type-checking
|
|
190
|
+
- `pnpm build` – compile JS and type definitions
|
|
191
|
+
- `pnpm test:typecheck` – strict type-checking
|
|
86
192
|
- `pnpm lint` / `pnpm format` – Biome-powered linting and formatting
|
|
193
|
+
|
|
194
|
+
## More resources
|
|
195
|
+
|
|
196
|
+
- Playground: `examples/vite-react` (run with `pnpm install && pnpm dev`).
|
|
197
|
+
- Next.js reference app: `examples/nextjs`.
|
|
198
|
+
- Client APIs live in `src/actions.ts`, `src/watchers`, and `src/features/*` for helper internals.
|