@solana/connector 0.0.0 → 0.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 +1460 -0
- package/dist/chunk-52WUWW5R.mjs +2533 -0
- package/dist/chunk-52WUWW5R.mjs.map +1 -0
- package/dist/chunk-5NSUFMCB.js +393 -0
- package/dist/chunk-5NSUFMCB.js.map +1 -0
- package/dist/chunk-5ZUVZZWU.mjs +180 -0
- package/dist/chunk-5ZUVZZWU.mjs.map +1 -0
- package/dist/chunk-7TADXRFD.mjs +298 -0
- package/dist/chunk-7TADXRFD.mjs.map +1 -0
- package/dist/chunk-ACFSCMUI.mjs +359 -0
- package/dist/chunk-ACFSCMUI.mjs.map +1 -0
- package/dist/chunk-SGAIPK7Q.js +314 -0
- package/dist/chunk-SGAIPK7Q.js.map +1 -0
- package/dist/chunk-SMUUAKC3.js +186 -0
- package/dist/chunk-SMUUAKC3.js.map +1 -0
- package/dist/chunk-ZLPQUOFK.js +2594 -0
- package/dist/chunk-ZLPQUOFK.js.map +1 -0
- package/dist/compat.d.mts +106 -0
- package/dist/compat.d.ts +106 -0
- package/dist/compat.js +98 -0
- package/dist/compat.js.map +1 -0
- package/dist/compat.mjs +94 -0
- package/dist/compat.mjs.map +1 -0
- package/dist/headless.d.mts +400 -0
- package/dist/headless.d.ts +400 -0
- package/dist/headless.js +325 -0
- package/dist/headless.js.map +1 -0
- package/dist/headless.mjs +4 -0
- package/dist/headless.mjs.map +1 -0
- package/dist/index.d.mts +10 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +382 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +645 -0
- package/dist/react.d.ts +645 -0
- package/dist/react.js +65 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +4 -0
- package/dist/react.mjs.map +1 -0
- package/dist/transaction-signer-BtJPGXIg.d.mts +373 -0
- package/dist/transaction-signer-BtJPGXIg.d.ts +373 -0
- package/dist/wallet-standard-shim-Af7ejSld.d.mts +1090 -0
- package/dist/wallet-standard-shim-BGlvGRbB.d.ts +1090 -0
- package/package.json +87 -10
- package/index.js +0 -1
package/dist/react.d.mts
ADDED
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
import { h as UnifiedConfig, d as ConnectorConfig, M as MobileWalletAdapterConfig, i as ClusterType, A as AccountInfo, N as ClipboardResult } from './wallet-standard-shim-Af7ejSld.mjs';
|
|
2
|
+
export { b as ConnectorErrorBoundary, C as ConnectorProvider, c as ConnectorSnapshot, e as ConnectorState, D as DefaultConfigOptions, E as ExtendedConnectorConfig, U as UnifiedConfigOptions, W as WalletInfo, g as WalletStandardAccount, f as WalletStandardWallet, u as useConnector, a as useConnectorClient, w as withErrorBoundary } from './wallet-standard-shim-Af7ejSld.mjs';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode, ComponentType, PropsWithChildren } from 'react';
|
|
5
|
+
import { SolanaCluster, SolanaClusterId } from '@wallet-ui/core';
|
|
6
|
+
export { SolanaCluster, SolanaClusterId } from '@wallet-ui/core';
|
|
7
|
+
import { j as TransactionSigner, b as TransactionSignerCapabilities } from './transaction-signer-BtJPGXIg.mjs';
|
|
8
|
+
import { TransactionModifyingSigner, SolanaClient, CompilableTransactionMessage, TransactionMessageWithBlockhashLifetime } from 'gill';
|
|
9
|
+
export { Wallet, WalletAccount } from '@wallet-standard/base';
|
|
10
|
+
import '@solana/web3.js';
|
|
11
|
+
|
|
12
|
+
interface UnifiedProviderProps {
|
|
13
|
+
children: ReactNode;
|
|
14
|
+
config?: UnifiedConfig;
|
|
15
|
+
connectorConfig?: ConnectorConfig;
|
|
16
|
+
mobile?: MobileWalletAdapterConfig;
|
|
17
|
+
providers?: Array<{
|
|
18
|
+
component: ComponentType<PropsWithChildren>;
|
|
19
|
+
props?: Record<string, unknown>;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
declare function UnifiedProvider({ children, config, connectorConfig, mobile, providers }: UnifiedProviderProps): react_jsx_runtime.JSX.Element;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @solana/connector - useCluster hook
|
|
26
|
+
*
|
|
27
|
+
* React hook for managing Solana cluster (network) state
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
interface UseClusterReturn {
|
|
31
|
+
/** Currently active cluster */
|
|
32
|
+
cluster: SolanaCluster | null;
|
|
33
|
+
/** All available clusters */
|
|
34
|
+
clusters: SolanaCluster[];
|
|
35
|
+
/** Set the active cluster */
|
|
36
|
+
setCluster: (id: SolanaClusterId) => Promise<void>;
|
|
37
|
+
/** Whether the current cluster is mainnet */
|
|
38
|
+
isMainnet: boolean;
|
|
39
|
+
/** Whether the current cluster is devnet */
|
|
40
|
+
isDevnet: boolean;
|
|
41
|
+
/** Whether the current cluster is testnet */
|
|
42
|
+
isTestnet: boolean;
|
|
43
|
+
/** Whether the current cluster is running locally */
|
|
44
|
+
isLocal: boolean;
|
|
45
|
+
/** Solana Explorer base URL for the current cluster */
|
|
46
|
+
explorerUrl: string;
|
|
47
|
+
/** Cluster type (mainnet, devnet, testnet, localnet, custom) */
|
|
48
|
+
type: ClusterType | null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Hook for managing Solana cluster (network) selection
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* function ClusterSwitcher() {
|
|
56
|
+
* const { cluster, clusters, setCluster, isMainnet } = useCluster()
|
|
57
|
+
*
|
|
58
|
+
* return (
|
|
59
|
+
* <select
|
|
60
|
+
* value={cluster?.id}
|
|
61
|
+
* onChange={(e) => setCluster(e.target.value as SolanaClusterId)}
|
|
62
|
+
* >
|
|
63
|
+
* {clusters.map(c => (
|
|
64
|
+
* <option key={c.id} value={c.id}>{c.label}</option>
|
|
65
|
+
* ))}
|
|
66
|
+
* </select>
|
|
67
|
+
* )
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function useCluster(): UseClusterReturn;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @solana/connector - useAccount hook
|
|
75
|
+
*
|
|
76
|
+
* React hook for working with the connected wallet account
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
interface UseAccountReturn {
|
|
80
|
+
/** The connected wallet address */
|
|
81
|
+
address: string | null;
|
|
82
|
+
/** Full account info object */
|
|
83
|
+
account: AccountInfo | null;
|
|
84
|
+
/** Whether a wallet is connected */
|
|
85
|
+
connected: boolean;
|
|
86
|
+
/** Shortened formatted address for display */
|
|
87
|
+
formatted: string;
|
|
88
|
+
/** Copy the address to clipboard with enhanced result */
|
|
89
|
+
copy: () => Promise<ClipboardResult>;
|
|
90
|
+
/** Whether the address was recently copied */
|
|
91
|
+
copied: boolean;
|
|
92
|
+
/** All available accounts from the connected wallet */
|
|
93
|
+
accounts: AccountInfo[];
|
|
94
|
+
/** Select a different account from the connected wallet */
|
|
95
|
+
selectAccount: (address: string) => Promise<void>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Hook for working with the connected wallet account
|
|
99
|
+
* Provides formatted address, clipboard copying, and account selection
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```tsx
|
|
103
|
+
* function AccountDisplay() {
|
|
104
|
+
* const { address, formatted, copy, copied, connected } = useAccount()
|
|
105
|
+
*
|
|
106
|
+
* if (!connected) return <p>Not connected</p>
|
|
107
|
+
*
|
|
108
|
+
* return (
|
|
109
|
+
* <button onClick={copy}>
|
|
110
|
+
* {formatted} {copied && '✓'}
|
|
111
|
+
* </button>
|
|
112
|
+
* )
|
|
113
|
+
* }
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
declare function useAccount(): UseAccountReturn;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @solana/connector - useWalletInfo hook
|
|
120
|
+
*
|
|
121
|
+
* React hook for getting information about the connected wallet
|
|
122
|
+
*/
|
|
123
|
+
/**
|
|
124
|
+
* Simplified wallet information for display purposes
|
|
125
|
+
*/
|
|
126
|
+
interface WalletDisplayInfo {
|
|
127
|
+
/** Wallet name */
|
|
128
|
+
name: string;
|
|
129
|
+
/** Wallet icon/logo URL if available */
|
|
130
|
+
icon?: string;
|
|
131
|
+
/** Whether the wallet extension is installed */
|
|
132
|
+
installed: boolean;
|
|
133
|
+
/** Whether the wallet supports Solana connections */
|
|
134
|
+
connectable?: boolean;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Return value from useWalletInfo hook
|
|
138
|
+
*/
|
|
139
|
+
interface UseWalletInfoReturn {
|
|
140
|
+
/** Name of the connected wallet (e.g., 'Phantom', 'Solflare') */
|
|
141
|
+
name: string | null;
|
|
142
|
+
/** Wallet icon/logo URL if available */
|
|
143
|
+
icon: string | null;
|
|
144
|
+
/** Whether the wallet extension is installed */
|
|
145
|
+
installed: boolean;
|
|
146
|
+
/** Whether the wallet supports Solana connections */
|
|
147
|
+
connectable: boolean;
|
|
148
|
+
/** Whether currently connected to the wallet */
|
|
149
|
+
connected: boolean;
|
|
150
|
+
/** Whether a connection attempt is in progress */
|
|
151
|
+
connecting: boolean;
|
|
152
|
+
/** All available wallets */
|
|
153
|
+
wallets: WalletDisplayInfo[];
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Hook for getting information about the connected wallet
|
|
157
|
+
* Provides wallet metadata, connection status, and capabilities
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* ```tsx
|
|
161
|
+
* function WalletBadge() {
|
|
162
|
+
* const { name, icon, connected, connecting } = useWalletInfo()
|
|
163
|
+
*
|
|
164
|
+
* if (connecting) return <p>Connecting...</p>
|
|
165
|
+
* if (!connected) return <p>No wallet connected</p>
|
|
166
|
+
*
|
|
167
|
+
* return (
|
|
168
|
+
* <div>
|
|
169
|
+
* {icon && <img src={icon} alt={name} />}
|
|
170
|
+
* <span>{name}</span>
|
|
171
|
+
* </div>
|
|
172
|
+
* )
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
declare function useWalletInfo(): UseWalletInfoReturn;
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* @solana/connector - useTransactionSigner hook
|
|
180
|
+
*
|
|
181
|
+
* React hook for transaction signing operations
|
|
182
|
+
* Provides a clean interface for signing and sending transactions
|
|
183
|
+
* with automatic signer creation and lifecycle management
|
|
184
|
+
*/
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Return value from useTransactionSigner hook
|
|
188
|
+
*/
|
|
189
|
+
interface UseTransactionSignerReturn {
|
|
190
|
+
/**
|
|
191
|
+
* Transaction signer instance (null if not connected)
|
|
192
|
+
* Use this to sign and send transactions
|
|
193
|
+
*/
|
|
194
|
+
signer: TransactionSigner | null;
|
|
195
|
+
/**
|
|
196
|
+
* Whether a signer is available and ready to use
|
|
197
|
+
* Useful for disabling transaction buttons
|
|
198
|
+
*/
|
|
199
|
+
ready: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Current wallet address that will sign transactions
|
|
202
|
+
* Null if no wallet connected
|
|
203
|
+
*/
|
|
204
|
+
address: string | null;
|
|
205
|
+
/**
|
|
206
|
+
* Signer capabilities (what operations are supported)
|
|
207
|
+
* Always available even if signer is null (shows all false)
|
|
208
|
+
*/
|
|
209
|
+
capabilities: TransactionSignerCapabilities;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Hook for transaction signing operations
|
|
213
|
+
*
|
|
214
|
+
* Automatically creates a TransactionSigner when a wallet is connected,
|
|
215
|
+
* and provides convenient state for building transaction UIs.
|
|
216
|
+
*
|
|
217
|
+
* The signer is automatically recreated when:
|
|
218
|
+
* - Wallet connection state changes
|
|
219
|
+
* - Selected account changes
|
|
220
|
+
* - Active cluster/network changes
|
|
221
|
+
*
|
|
222
|
+
* @example
|
|
223
|
+
* ```tsx
|
|
224
|
+
* function SendTransaction() {
|
|
225
|
+
* const { signer, ready, capabilities } = useTransactionSigner()
|
|
226
|
+
* const [txSignature, setTxSignature] = useState<string | null>(null)
|
|
227
|
+
* const [error, setError] = useState<string | null>(null)
|
|
228
|
+
*
|
|
229
|
+
* const handleSend = async () => {
|
|
230
|
+
* if (!signer) return
|
|
231
|
+
*
|
|
232
|
+
* try {
|
|
233
|
+
* const signature = await signer.signAndSendTransaction(transaction)
|
|
234
|
+
* setTxSignature(signature)
|
|
235
|
+
* setError(null)
|
|
236
|
+
* } catch (err) {
|
|
237
|
+
* setError(err instanceof Error ? err.message : 'Transaction failed')
|
|
238
|
+
* }
|
|
239
|
+
* }
|
|
240
|
+
*
|
|
241
|
+
* return (
|
|
242
|
+
* <div>
|
|
243
|
+
* <button onClick={handleSend} disabled={!ready}>
|
|
244
|
+
* {ready ? 'Send Transaction' : 'Connect Wallet'}
|
|
245
|
+
* </button>
|
|
246
|
+
*
|
|
247
|
+
* {!capabilities.canSend && ready && (
|
|
248
|
+
* <p className="warning">
|
|
249
|
+
* Your wallet doesn't support direct sending.
|
|
250
|
+
* Transaction must be signed and broadcast separately.
|
|
251
|
+
* </p>
|
|
252
|
+
* )}
|
|
253
|
+
*
|
|
254
|
+
* {txSignature && (
|
|
255
|
+
* <p>Transaction sent: {txSignature}</p>
|
|
256
|
+
* )}
|
|
257
|
+
*
|
|
258
|
+
* {error && (
|
|
259
|
+
* <p className="error">{error}</p>
|
|
260
|
+
* )}
|
|
261
|
+
* </div>
|
|
262
|
+
* )
|
|
263
|
+
* }
|
|
264
|
+
* ```
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```tsx
|
|
268
|
+
* // Using with multiple transactions
|
|
269
|
+
* function SendBatch() {
|
|
270
|
+
* const { signer, ready, capabilities } = useTransactionSigner()
|
|
271
|
+
*
|
|
272
|
+
* const handleSendBatch = async () => {
|
|
273
|
+
* if (!signer) return
|
|
274
|
+
*
|
|
275
|
+
* const transactions = [tx1, tx2, tx3]
|
|
276
|
+
*
|
|
277
|
+
* // Check if batch signing is supported
|
|
278
|
+
* if (capabilities.supportsBatchSigning) {
|
|
279
|
+
* // More efficient: sign all at once
|
|
280
|
+
* const signed = await signer.signAllTransactions(transactions)
|
|
281
|
+
* // ... send signed transactions
|
|
282
|
+
* } else {
|
|
283
|
+
* // Fallback: sign and send one by one
|
|
284
|
+
* const signatures = await signer.signAndSendTransactions(transactions)
|
|
285
|
+
* console.log('All sent:', signatures)
|
|
286
|
+
* }
|
|
287
|
+
* }
|
|
288
|
+
*
|
|
289
|
+
* return (
|
|
290
|
+
* <button onClick={handleSendBatch} disabled={!ready}>
|
|
291
|
+
* Send {capabilities.supportsBatchSigning ? 'Batch' : 'Sequential'}
|
|
292
|
+
* </button>
|
|
293
|
+
* )
|
|
294
|
+
* }
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* @example
|
|
298
|
+
* ```tsx
|
|
299
|
+
* // Using with message signing for authentication
|
|
300
|
+
* function SignInWithWallet() {
|
|
301
|
+
* const { signer, ready, capabilities } = useTransactionSigner()
|
|
302
|
+
*
|
|
303
|
+
* const handleSignIn = async () => {
|
|
304
|
+
* if (!signer || !capabilities.canSignMessage) {
|
|
305
|
+
* alert('Wallet does not support message signing')
|
|
306
|
+
* return
|
|
307
|
+
* }
|
|
308
|
+
*
|
|
309
|
+
* const message = new TextEncoder().encode('Sign in to MyApp')
|
|
310
|
+
* const signature = await signer.signMessage!(message)
|
|
311
|
+
*
|
|
312
|
+
* // Send signature to backend for verification
|
|
313
|
+
* await fetch('/api/auth/verify', {
|
|
314
|
+
* method: 'POST',
|
|
315
|
+
* body: JSON.stringify({
|
|
316
|
+
* message: Array.from(message),
|
|
317
|
+
* signature: Array.from(signature),
|
|
318
|
+
* address: signer.address
|
|
319
|
+
* })
|
|
320
|
+
* })
|
|
321
|
+
* }
|
|
322
|
+
*
|
|
323
|
+
* if (!capabilities.canSignMessage) {
|
|
324
|
+
* return <p>Message signing not supported</p>
|
|
325
|
+
* }
|
|
326
|
+
*
|
|
327
|
+
* return (
|
|
328
|
+
* <button onClick={handleSignIn} disabled={!ready}>
|
|
329
|
+
* Sign In with Wallet
|
|
330
|
+
* </button>
|
|
331
|
+
* )
|
|
332
|
+
* }
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
declare function useTransactionSigner(): UseTransactionSignerReturn;
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* @solana/connector - useGillTransactionSigner hook
|
|
339
|
+
*
|
|
340
|
+
* React hook for gill-compatible transaction signing
|
|
341
|
+
* Use this when working with modern Solana libraries (@solana/kit, gill)
|
|
342
|
+
*/
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Return value from useGillTransactionSigner hook
|
|
346
|
+
*/
|
|
347
|
+
interface UseGillTransactionSignerReturn {
|
|
348
|
+
/**
|
|
349
|
+
* Gill-compatible TransactionModifyingSigner instance (null if not connected)
|
|
350
|
+
* Use this with modern Solana libraries (@solana/kit, gill)
|
|
351
|
+
*/
|
|
352
|
+
signer: TransactionModifyingSigner | null;
|
|
353
|
+
/**
|
|
354
|
+
* Whether a signer is available and ready to use
|
|
355
|
+
* Useful for disabling transaction buttons
|
|
356
|
+
*/
|
|
357
|
+
ready: boolean;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Hook for gill-compatible transaction signing
|
|
361
|
+
*
|
|
362
|
+
* Creates a TransactionPartialSigner that's compatible with @solana/kit and gill,
|
|
363
|
+
* enabling seamless integration with modern Solana development patterns.
|
|
364
|
+
*
|
|
365
|
+
* This hook wraps the standard useTransactionSigner and adapts it to gill's
|
|
366
|
+
* interface, allowing you to use modern libraries without type incompatibilities.
|
|
367
|
+
*
|
|
368
|
+
* @example
|
|
369
|
+
* ```tsx
|
|
370
|
+
* import { useGillTransactionSigner } from '@solana/connector';
|
|
371
|
+
* import { getTransferSolInstruction } from 'gill/programs';
|
|
372
|
+
* import { address, pipe, createTransactionMessage } from 'gill';
|
|
373
|
+
*
|
|
374
|
+
* function ModernTransfer() {
|
|
375
|
+
* const { signer, ready } = useGillTransactionSigner();
|
|
376
|
+
*
|
|
377
|
+
* const handleTransfer = async (recipient: string, amount: number) => {
|
|
378
|
+
* if (!signer) return;
|
|
379
|
+
*
|
|
380
|
+
* // Fully type-safe with gill!
|
|
381
|
+
* const instruction = getTransferSolInstruction({
|
|
382
|
+
* source: signer, // No type errors
|
|
383
|
+
* destination: address(recipient),
|
|
384
|
+
* amount
|
|
385
|
+
* });
|
|
386
|
+
*
|
|
387
|
+
* const txMessage = pipe(
|
|
388
|
+
* createTransactionMessage({ version: 0 }),
|
|
389
|
+
* (tx) => setTransactionMessageFeePayerSigner(signer, tx), // Works!
|
|
390
|
+
* // ...
|
|
391
|
+
* );
|
|
392
|
+
* };
|
|
393
|
+
*
|
|
394
|
+
* return (
|
|
395
|
+
* <button onClick={handleTransfer} disabled={!ready}>
|
|
396
|
+
* Send with Gill
|
|
397
|
+
* </button>
|
|
398
|
+
* );
|
|
399
|
+
* }
|
|
400
|
+
* ```
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```tsx
|
|
404
|
+
* // For backward compatibility, continue using useTransactionSigner
|
|
405
|
+
* import { useTransactionSigner } from '@solana/connector';
|
|
406
|
+
*
|
|
407
|
+
* function LegacyTransfer() {
|
|
408
|
+
* const { signer } = useTransactionSigner(); // Wallet adapter compatible
|
|
409
|
+
* // Works with @solana/web3.js v1 and wallet-adapter
|
|
410
|
+
* }
|
|
411
|
+
* ```
|
|
412
|
+
*/
|
|
413
|
+
declare function useGillTransactionSigner(): UseGillTransactionSignerReturn;
|
|
414
|
+
|
|
415
|
+
/**
|
|
416
|
+
* @solana/connector - useGillSolanaClient hook
|
|
417
|
+
*
|
|
418
|
+
* React hook for Gill's SolanaClient with built-in RPC and WebSocket subscriptions
|
|
419
|
+
* Provides rpc, rpcSubscriptions, sendAndConfirmTransaction, and simulateTransaction
|
|
420
|
+
*/
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Return value from useGillSolanaClient hook
|
|
424
|
+
*/
|
|
425
|
+
interface UseGillSolanaClientReturn {
|
|
426
|
+
/**
|
|
427
|
+
* Gill SolanaClient instance with RPC and subscriptions (null if not available)
|
|
428
|
+
* Includes: rpc, rpcSubscriptions, sendAndConfirmTransaction, simulateTransaction
|
|
429
|
+
*/
|
|
430
|
+
client: SolanaClient | null;
|
|
431
|
+
/**
|
|
432
|
+
* Whether a client is available and ready to use
|
|
433
|
+
*/
|
|
434
|
+
ready: boolean;
|
|
435
|
+
/**
|
|
436
|
+
* Cluster type (mainnet, devnet, testnet, localnet, custom)
|
|
437
|
+
*/
|
|
438
|
+
clusterType: ClusterType | null;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Hook for Gill's SolanaClient with automatic RPC and WebSocket subscription management
|
|
442
|
+
*
|
|
443
|
+
* Creates a fully configured SolanaClient based on the current cluster, providing:
|
|
444
|
+
* - Type-safe RPC client
|
|
445
|
+
* - WebSocket subscription client
|
|
446
|
+
* - Built-in sendAndConfirmTransaction helper
|
|
447
|
+
* - Built-in simulateTransaction helper
|
|
448
|
+
*
|
|
449
|
+
* The client is automatically recreated when the cluster changes.
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```tsx
|
|
453
|
+
* import { useGillSolanaClient, useGillTransactionSigner } from '@solana/connector';
|
|
454
|
+
* import { signTransactionMessageWithSigners } from 'gill';
|
|
455
|
+
*
|
|
456
|
+
* function SendTransaction() {
|
|
457
|
+
* const { client, ready } = useGillSolanaClient();
|
|
458
|
+
* const { signer } = useGillTransactionSigner();
|
|
459
|
+
*
|
|
460
|
+
* const handleSend = async (transaction) => {
|
|
461
|
+
* if (!client || !signer) return;
|
|
462
|
+
*
|
|
463
|
+
* // Sign the transaction
|
|
464
|
+
* const signed = await signTransactionMessageWithSigners(transaction);
|
|
465
|
+
*
|
|
466
|
+
* // Send and confirm using Gill's built-in helper
|
|
467
|
+
* await client.sendAndConfirmTransaction(signed, {
|
|
468
|
+
* commitment: 'confirmed'
|
|
469
|
+
* });
|
|
470
|
+
* };
|
|
471
|
+
*
|
|
472
|
+
* return (
|
|
473
|
+
* <button onClick={handleSend} disabled={!ready}>
|
|
474
|
+
* Send Transaction
|
|
475
|
+
* </button>
|
|
476
|
+
* );
|
|
477
|
+
* }
|
|
478
|
+
* ```
|
|
479
|
+
*
|
|
480
|
+
* @example
|
|
481
|
+
* ```tsx
|
|
482
|
+
* // Simulating a transaction
|
|
483
|
+
* function SimulateTransaction() {
|
|
484
|
+
* const { client } = useGillSolanaClient();
|
|
485
|
+
*
|
|
486
|
+
* const handleSimulate = async (transaction) => {
|
|
487
|
+
* if (!client) return;
|
|
488
|
+
*
|
|
489
|
+
* const simulation = await client.simulateTransaction(transaction, {
|
|
490
|
+
* sigVerify: false,
|
|
491
|
+
* commitment: 'processed'
|
|
492
|
+
* });
|
|
493
|
+
*
|
|
494
|
+
* console.log('Simulation result:', simulation);
|
|
495
|
+
* };
|
|
496
|
+
* }
|
|
497
|
+
* ```
|
|
498
|
+
*
|
|
499
|
+
* @example
|
|
500
|
+
* ```tsx
|
|
501
|
+
* // Direct RPC access
|
|
502
|
+
* function GetBalance() {
|
|
503
|
+
* const { client } = useGillSolanaClient();
|
|
504
|
+
*
|
|
505
|
+
* const fetchBalance = async (address: Address) => {
|
|
506
|
+
* if (!client) return;
|
|
507
|
+
*
|
|
508
|
+
* const balance = await client.rpc.getBalance(address).send();
|
|
509
|
+
* console.log('Balance:', balance);
|
|
510
|
+
* };
|
|
511
|
+
* }
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
declare function useGillSolanaClient(): UseGillSolanaClientReturn;
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* @solana/connector - useTransactionPreparer hook
|
|
518
|
+
*
|
|
519
|
+
* React hook for preparing transactions with automatic optimization
|
|
520
|
+
* Handles blockhash fetching, compute unit limits, and transaction simulation
|
|
521
|
+
*/
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* Options for transaction preparation
|
|
525
|
+
*/
|
|
526
|
+
interface TransactionPrepareOptions {
|
|
527
|
+
/**
|
|
528
|
+
* Multiplier applied to the simulated compute unit value
|
|
529
|
+
* @default 1.1 (10% buffer)
|
|
530
|
+
*/
|
|
531
|
+
computeUnitLimitMultiplier?: number;
|
|
532
|
+
/**
|
|
533
|
+
* Whether to force reset the compute unit limit value (if one is already set)
|
|
534
|
+
* using the simulation response and computeUnitLimitMultiplier
|
|
535
|
+
* @default false
|
|
536
|
+
*/
|
|
537
|
+
computeUnitLimitReset?: boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Whether to force reset the latest blockhash (if one is already set)
|
|
540
|
+
* @default true
|
|
541
|
+
*/
|
|
542
|
+
blockhashReset?: boolean;
|
|
543
|
+
}
|
|
544
|
+
/**
|
|
545
|
+
* Return value from useTransactionPreparer hook
|
|
546
|
+
*/
|
|
547
|
+
interface UseTransactionPreparerReturn {
|
|
548
|
+
/**
|
|
549
|
+
* Prepare a transaction for sending
|
|
550
|
+
* Automatically adds:
|
|
551
|
+
* - Compute unit limit (via simulation with optional multiplier)
|
|
552
|
+
* - Latest blockhash (if not already set)
|
|
553
|
+
*
|
|
554
|
+
* @param transaction - The transaction to prepare
|
|
555
|
+
* @param options - Optional preparation settings
|
|
556
|
+
* @returns Prepared transaction with blockhash lifetime set
|
|
557
|
+
*/
|
|
558
|
+
prepare: <TMessage extends CompilableTransactionMessage>(transaction: TMessage, options?: TransactionPrepareOptions) => Promise<TMessage & TransactionMessageWithBlockhashLifetime>;
|
|
559
|
+
/**
|
|
560
|
+
* Whether the preparer is ready to use
|
|
561
|
+
* False if Solana client is not available
|
|
562
|
+
*/
|
|
563
|
+
ready: boolean;
|
|
564
|
+
}
|
|
565
|
+
/**
|
|
566
|
+
* Hook for preparing transactions with automatic optimization
|
|
567
|
+
*
|
|
568
|
+
* Uses Gill's prepareTransaction utility to:
|
|
569
|
+
* 1. Simulate the transaction to determine optimal compute units
|
|
570
|
+
* 2. Set compute unit limit (with configurable multiplier for safety margin)
|
|
571
|
+
* 3. Fetch and set the latest blockhash (if not already present)
|
|
572
|
+
*
|
|
573
|
+
* This significantly improves transaction landing rates by ensuring proper
|
|
574
|
+
* compute budget allocation and fresh blockhashes.
|
|
575
|
+
*
|
|
576
|
+
* @example
|
|
577
|
+
* ```tsx
|
|
578
|
+
* import { useTransactionPreparer, useGillTransactionSigner } from '@solana/connector';
|
|
579
|
+
* import { pipe, createTransactionMessage, appendTransactionMessageInstructions } from 'gill';
|
|
580
|
+
* import { getTransferSolInstruction } from 'gill/programs';
|
|
581
|
+
*
|
|
582
|
+
* function SendOptimizedTransaction() {
|
|
583
|
+
* const { prepare, ready } = useTransactionPreparer();
|
|
584
|
+
* const { signer } = useGillTransactionSigner();
|
|
585
|
+
* const { client } = useGillSolanaClient();
|
|
586
|
+
*
|
|
587
|
+
* const handleSend = async (recipient: string, amount: bigint) => {
|
|
588
|
+
* if (!ready || !signer || !client) return;
|
|
589
|
+
*
|
|
590
|
+
* // Build transaction message
|
|
591
|
+
* const tx = pipe(
|
|
592
|
+
* createTransactionMessage({ version: 0 }),
|
|
593
|
+
* tx => setTransactionMessageFeePayerSigner(signer, tx),
|
|
594
|
+
* tx => appendTransactionMessageInstructions([
|
|
595
|
+
* getTransferSolInstruction({
|
|
596
|
+
* source: signer,
|
|
597
|
+
* destination: address(recipient),
|
|
598
|
+
* amount: lamports(amount),
|
|
599
|
+
* })
|
|
600
|
+
* ], tx)
|
|
601
|
+
* );
|
|
602
|
+
*
|
|
603
|
+
* // Prepare: auto-adds compute units + blockhash
|
|
604
|
+
* const prepared = await prepare(tx);
|
|
605
|
+
*
|
|
606
|
+
* // Sign
|
|
607
|
+
* const signed = await signTransactionMessageWithSigners(prepared);
|
|
608
|
+
*
|
|
609
|
+
* // Send and confirm
|
|
610
|
+
* await client.sendAndConfirmTransaction(signed);
|
|
611
|
+
* };
|
|
612
|
+
*
|
|
613
|
+
* return (
|
|
614
|
+
* <button onClick={handleSend} disabled={!ready}>
|
|
615
|
+
* Send Optimized Transaction
|
|
616
|
+
* </button>
|
|
617
|
+
* );
|
|
618
|
+
* }
|
|
619
|
+
* ```
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* ```tsx
|
|
623
|
+
* // With custom compute unit multiplier for high-priority transactions
|
|
624
|
+
* const { prepare } = useTransactionPreparer();
|
|
625
|
+
*
|
|
626
|
+
* const prepared = await prepare(transaction, {
|
|
627
|
+
* computeUnitLimitMultiplier: 1.3, // 30% buffer instead of default 10%
|
|
628
|
+
* blockhashReset: true // Always fetch fresh blockhash
|
|
629
|
+
* });
|
|
630
|
+
* ```
|
|
631
|
+
*
|
|
632
|
+
* @example
|
|
633
|
+
* ```tsx
|
|
634
|
+
* // Force reset compute units even if already set
|
|
635
|
+
* const { prepare } = useTransactionPreparer();
|
|
636
|
+
*
|
|
637
|
+
* const prepared = await prepare(transaction, {
|
|
638
|
+
* computeUnitLimitReset: true, // Re-simulate and reset compute units
|
|
639
|
+
* computeUnitLimitMultiplier: 1.2
|
|
640
|
+
* });
|
|
641
|
+
* ```
|
|
642
|
+
*/
|
|
643
|
+
declare function useTransactionPreparer(): UseTransactionPreparerReturn;
|
|
644
|
+
|
|
645
|
+
export { AccountInfo, UnifiedProvider as AppProvider, ClusterType, ConnectorConfig, MobileWalletAdapterConfig, type TransactionPrepareOptions, UnifiedConfig, UnifiedProvider, type UnifiedProviderProps, type UseAccountReturn, type UseClusterReturn, type UseGillSolanaClientReturn, type UseGillTransactionSignerReturn, type UseTransactionPreparerReturn, type UseTransactionSignerReturn, type UseWalletInfoReturn, useAccount, useCluster, useGillSolanaClient, useGillTransactionSigner, useTransactionPreparer, useTransactionSigner, useWalletInfo };
|