@phantom/react-sdk 0.3.8 → 1.0.0-beta.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 +401 -246
- package/dist/index.d.ts +62 -16
- package/dist/index.js +254 -81
- package/dist/index.mjs +249 -76
- package/package.json +4 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import { BrowserSDKConfig, DebugConfig, AuthOptions, BrowserSDK, WalletAddress,
|
|
4
|
-
export { AddressType,
|
|
3
|
+
import { BrowserSDKConfig, DebugConfig, AuthOptions, BrowserSDK, WalletAddress, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult } from '@phantom/browser-sdk';
|
|
4
|
+
export { AddressType, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult, DebugLevel, DebugMessage, NetworkId, SignedTransaction, WalletAddress, debug } from '@phantom/browser-sdk';
|
|
5
5
|
import * as _phantom_embedded_provider_core from '@phantom/embedded-provider-core';
|
|
6
|
+
import * as _phantom_parsers from '@phantom/parsers';
|
|
7
|
+
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chains';
|
|
8
|
+
export { EthTransactionRequest, IEthereumChain, ISolanaChain } from '@phantom/chains';
|
|
6
9
|
|
|
7
10
|
interface PhantomSDKConfig extends BrowserSDKConfig {
|
|
8
11
|
}
|
|
@@ -32,7 +35,7 @@ declare function PhantomProvider({ children, config, debugConfig }: PhantomProvi
|
|
|
32
35
|
declare function usePhantom(): PhantomContextValue;
|
|
33
36
|
|
|
34
37
|
declare function useConnect(): {
|
|
35
|
-
connect: (options?:
|
|
38
|
+
connect: (options?: AuthOptions) => Promise<_phantom_embedded_provider_core.ConnectResult>;
|
|
36
39
|
isConnecting: boolean;
|
|
37
40
|
error: Error | null;
|
|
38
41
|
currentProviderType: "injected" | "embedded" | null;
|
|
@@ -45,18 +48,6 @@ declare function useDisconnect(): {
|
|
|
45
48
|
error: Error | null;
|
|
46
49
|
};
|
|
47
50
|
|
|
48
|
-
declare function useSignMessage(): {
|
|
49
|
-
signMessage: (params: SignMessageParams) => Promise<SignMessageResult>;
|
|
50
|
-
isSigning: boolean;
|
|
51
|
-
error: Error | null;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
declare function useSignAndSendTransaction(): {
|
|
55
|
-
signAndSendTransaction: (params: SignAndSendTransactionParams) => Promise<SignedTransaction>;
|
|
56
|
-
isSigning: boolean;
|
|
57
|
-
error: Error | null;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
51
|
declare function useAccounts(): _phantom_embedded_provider_core.WalletAddress[] | null;
|
|
61
52
|
|
|
62
53
|
declare function useIsExtensionInstalled(): {
|
|
@@ -64,6 +55,61 @@ declare function useIsExtensionInstalled(): {
|
|
|
64
55
|
isInstalled: boolean;
|
|
65
56
|
};
|
|
66
57
|
|
|
58
|
+
interface UseAutoConfirmResult {
|
|
59
|
+
enable: (params: AutoConfirmEnableParams) => Promise<AutoConfirmResult>;
|
|
60
|
+
disable: () => Promise<void>;
|
|
61
|
+
status: AutoConfirmResult | null;
|
|
62
|
+
supportedChains: AutoConfirmSupportedChainsResult | null;
|
|
63
|
+
isLoading: boolean;
|
|
64
|
+
error: Error | null;
|
|
65
|
+
refetch: () => Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
declare function useAutoConfirm(): UseAutoConfirmResult;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Hook for Solana chain operations
|
|
71
|
+
*
|
|
72
|
+
* @returns Solana chain interface and convenient methods
|
|
73
|
+
*/
|
|
74
|
+
declare function useSolana(): {
|
|
75
|
+
solana: ISolanaChain | null;
|
|
76
|
+
signMessage: (message: string | Uint8Array) => Promise<_phantom_parsers.ParsedSignatureResult>;
|
|
77
|
+
signTransaction: <T>(transaction: T) => Promise<T>;
|
|
78
|
+
signAndSendTransaction: <T>(transaction: T) => Promise<_phantom_parsers.ParsedTransactionResult>;
|
|
79
|
+
connect: (options?: {
|
|
80
|
+
onlyIfTrusted?: boolean;
|
|
81
|
+
}) => Promise<{
|
|
82
|
+
publicKey: string;
|
|
83
|
+
}>;
|
|
84
|
+
disconnect: () => Promise<void>;
|
|
85
|
+
switchNetwork: (network: "mainnet" | "devnet") => Promise<void>;
|
|
86
|
+
getPublicKey: () => Promise<string | null>;
|
|
87
|
+
isAvailable: boolean;
|
|
88
|
+
isConnected: boolean;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Hook for Ethereum chain operations
|
|
93
|
+
*
|
|
94
|
+
* @returns Ethereum chain interface and convenient methods
|
|
95
|
+
*/
|
|
96
|
+
declare function useEthereum(): {
|
|
97
|
+
ethereum: IEthereumChain | null;
|
|
98
|
+
request: <T = any>(args: {
|
|
99
|
+
method: string;
|
|
100
|
+
params?: unknown[];
|
|
101
|
+
}) => Promise<T>;
|
|
102
|
+
signPersonalMessage: (message: string, address: string) => Promise<string>;
|
|
103
|
+
signMessage: (message: string) => Promise<string>;
|
|
104
|
+
signTypedData: (typedData: any) => Promise<string>;
|
|
105
|
+
sendTransaction: (transaction: EthTransactionRequest) => Promise<_phantom_parsers.ParsedTransactionResult>;
|
|
106
|
+
switchChain: (chainId: number) => Promise<void>;
|
|
107
|
+
getChainId: () => Promise<number>;
|
|
108
|
+
getAccounts: () => Promise<string[]>;
|
|
109
|
+
isAvailable: boolean;
|
|
110
|
+
isConnected: boolean;
|
|
111
|
+
};
|
|
112
|
+
|
|
67
113
|
type ProviderType = "injected" | "embedded";
|
|
68
114
|
|
|
69
|
-
export { ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomProviderProps, PhantomSDKConfig, ProviderType, useAccounts, useConnect, useDisconnect, useIsExtensionInstalled, usePhantom,
|
|
115
|
+
export { ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomProviderProps, PhantomSDKConfig, ProviderType, useAccounts, useAutoConfirm, useConnect, useDisconnect, useEthereum, useIsExtensionInstalled, usePhantom, useSolana };
|
package/dist/index.js
CHANGED
|
@@ -30,18 +30,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
|
-
AddressType: () =>
|
|
34
|
-
DebugLevel: () =>
|
|
35
|
-
NetworkId: () =>
|
|
33
|
+
AddressType: () => import_browser_sdk3.AddressType,
|
|
34
|
+
DebugLevel: () => import_browser_sdk3.DebugLevel,
|
|
35
|
+
NetworkId: () => import_browser_sdk3.NetworkId,
|
|
36
36
|
PhantomProvider: () => PhantomProvider,
|
|
37
|
-
debug: () =>
|
|
37
|
+
debug: () => import_browser_sdk3.debug,
|
|
38
38
|
useAccounts: () => useAccounts,
|
|
39
|
+
useAutoConfirm: () => useAutoConfirm,
|
|
39
40
|
useConnect: () => useConnect,
|
|
40
41
|
useDisconnect: () => useDisconnect,
|
|
42
|
+
useEthereum: () => useEthereum,
|
|
41
43
|
useIsExtensionInstalled: () => useIsExtensionInstalled,
|
|
42
44
|
usePhantom: () => usePhantom,
|
|
43
|
-
|
|
44
|
-
useSignMessage: () => useSignMessage
|
|
45
|
+
useSolana: () => useSolana
|
|
45
46
|
});
|
|
46
47
|
module.exports = __toCommonJS(src_exports);
|
|
47
48
|
|
|
@@ -122,9 +123,9 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
122
123
|
(0, import_react.useEffect)(() => {
|
|
123
124
|
if (!sdk)
|
|
124
125
|
return;
|
|
125
|
-
const initialize =
|
|
126
|
+
const initialize = () => {
|
|
126
127
|
try {
|
|
127
|
-
const available =
|
|
128
|
+
const available = import_browser_sdk.BrowserSDK.isPhantomInstalled();
|
|
128
129
|
setIsPhantomAvailable(available);
|
|
129
130
|
} catch (err) {
|
|
130
131
|
console.error("Error checking Phantom extension:", err);
|
|
@@ -225,76 +226,6 @@ function useDisconnect() {
|
|
|
225
226
|
};
|
|
226
227
|
}
|
|
227
228
|
|
|
228
|
-
// src/hooks/useSignMessage.ts
|
|
229
|
-
var import_react4 = require("react");
|
|
230
|
-
function useSignMessage() {
|
|
231
|
-
const { sdk } = usePhantom();
|
|
232
|
-
const [isSigning, setIsSigning] = (0, import_react4.useState)(false);
|
|
233
|
-
const [error, setError] = (0, import_react4.useState)(null);
|
|
234
|
-
const signMessage = (0, import_react4.useCallback)(
|
|
235
|
-
async (params) => {
|
|
236
|
-
if (!sdk) {
|
|
237
|
-
throw new Error("SDK not initialized");
|
|
238
|
-
}
|
|
239
|
-
if (!sdk.isConnected()) {
|
|
240
|
-
throw new Error("Wallet not connected");
|
|
241
|
-
}
|
|
242
|
-
setIsSigning(true);
|
|
243
|
-
setError(null);
|
|
244
|
-
try {
|
|
245
|
-
const signature = await sdk.signMessage(params);
|
|
246
|
-
return signature;
|
|
247
|
-
} catch (err) {
|
|
248
|
-
setError(err);
|
|
249
|
-
throw err;
|
|
250
|
-
} finally {
|
|
251
|
-
setIsSigning(false);
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
[sdk]
|
|
255
|
-
);
|
|
256
|
-
return {
|
|
257
|
-
signMessage,
|
|
258
|
-
isSigning,
|
|
259
|
-
error
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// src/hooks/useSignAndSendTransaction.ts
|
|
264
|
-
var import_react5 = require("react");
|
|
265
|
-
function useSignAndSendTransaction() {
|
|
266
|
-
const { sdk } = usePhantom();
|
|
267
|
-
const [isSigning, setIsSigning] = (0, import_react5.useState)(false);
|
|
268
|
-
const [error, setError] = (0, import_react5.useState)(null);
|
|
269
|
-
const signAndSendTransaction = (0, import_react5.useCallback)(
|
|
270
|
-
async (params) => {
|
|
271
|
-
if (!sdk) {
|
|
272
|
-
throw new Error("SDK not initialized");
|
|
273
|
-
}
|
|
274
|
-
if (!sdk.isConnected()) {
|
|
275
|
-
throw new Error("Wallet not connected");
|
|
276
|
-
}
|
|
277
|
-
setIsSigning(true);
|
|
278
|
-
setError(null);
|
|
279
|
-
try {
|
|
280
|
-
const result = await sdk.signAndSendTransaction(params);
|
|
281
|
-
return result;
|
|
282
|
-
} catch (err) {
|
|
283
|
-
setError(err);
|
|
284
|
-
throw err;
|
|
285
|
-
} finally {
|
|
286
|
-
setIsSigning(false);
|
|
287
|
-
}
|
|
288
|
-
},
|
|
289
|
-
[sdk]
|
|
290
|
-
);
|
|
291
|
-
return {
|
|
292
|
-
signAndSendTransaction,
|
|
293
|
-
isSigning,
|
|
294
|
-
error
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
|
|
298
229
|
// src/hooks/useAccounts.ts
|
|
299
230
|
function useAccounts() {
|
|
300
231
|
const { addresses, isConnected } = usePhantom();
|
|
@@ -303,6 +234,7 @@ function useAccounts() {
|
|
|
303
234
|
|
|
304
235
|
// src/hooks/useIsExtensionInstalled.ts
|
|
305
236
|
var React = __toESM(require("react"));
|
|
237
|
+
var import_browser_sdk2 = require("@phantom/browser-sdk");
|
|
306
238
|
var cachedIsInstalled = null;
|
|
307
239
|
function useIsExtensionInstalled() {
|
|
308
240
|
const { sdk } = usePhantom();
|
|
@@ -318,10 +250,10 @@ function useIsExtensionInstalled() {
|
|
|
318
250
|
setIsLoading(false);
|
|
319
251
|
return;
|
|
320
252
|
}
|
|
321
|
-
const checkExtension =
|
|
253
|
+
const checkExtension = () => {
|
|
322
254
|
try {
|
|
323
255
|
setIsLoading(true);
|
|
324
|
-
const result =
|
|
256
|
+
const result = import_browser_sdk2.BrowserSDK.isPhantomInstalled();
|
|
325
257
|
cachedIsInstalled = result;
|
|
326
258
|
setIsInstalled(result);
|
|
327
259
|
} catch (error) {
|
|
@@ -336,5 +268,246 @@ function useIsExtensionInstalled() {
|
|
|
336
268
|
return { isLoading, isInstalled };
|
|
337
269
|
}
|
|
338
270
|
|
|
271
|
+
// src/hooks/useAutoConfirm.ts
|
|
272
|
+
var import_react4 = require("react");
|
|
273
|
+
function useAutoConfirm() {
|
|
274
|
+
const { sdk, currentProviderType } = usePhantom();
|
|
275
|
+
const [status, setStatus] = (0, import_react4.useState)(null);
|
|
276
|
+
const [supportedChains, setSupportedChains] = (0, import_react4.useState)(null);
|
|
277
|
+
const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
|
|
278
|
+
const [error, setError] = (0, import_react4.useState)(null);
|
|
279
|
+
const isInjected = currentProviderType === "injected";
|
|
280
|
+
const enable = (0, import_react4.useCallback)(
|
|
281
|
+
async (params) => {
|
|
282
|
+
if (!sdk) {
|
|
283
|
+
throw new Error("SDK not initialized");
|
|
284
|
+
}
|
|
285
|
+
if (!isInjected) {
|
|
286
|
+
throw new Error("Auto-confirm is only available for injected (extension) providers");
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
setIsLoading(true);
|
|
290
|
+
setError(null);
|
|
291
|
+
const result = await sdk.enableAutoConfirm(params);
|
|
292
|
+
setStatus(result);
|
|
293
|
+
return result;
|
|
294
|
+
} catch (err) {
|
|
295
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
296
|
+
setError(error2);
|
|
297
|
+
throw error2;
|
|
298
|
+
} finally {
|
|
299
|
+
setIsLoading(false);
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
[sdk, isInjected]
|
|
303
|
+
);
|
|
304
|
+
const disable = (0, import_react4.useCallback)(
|
|
305
|
+
async () => {
|
|
306
|
+
if (!sdk) {
|
|
307
|
+
throw new Error("SDK not initialized");
|
|
308
|
+
}
|
|
309
|
+
if (!isInjected) {
|
|
310
|
+
throw new Error("Auto-confirm is only available for injected (extension) providers");
|
|
311
|
+
}
|
|
312
|
+
try {
|
|
313
|
+
setIsLoading(true);
|
|
314
|
+
setError(null);
|
|
315
|
+
await sdk.disableAutoConfirm();
|
|
316
|
+
const newStatus = await sdk.getAutoConfirmStatus();
|
|
317
|
+
setStatus(newStatus);
|
|
318
|
+
} catch (err) {
|
|
319
|
+
const error2 = err instanceof Error ? err : new Error("Unknown error occurred");
|
|
320
|
+
setError(error2);
|
|
321
|
+
throw error2;
|
|
322
|
+
} finally {
|
|
323
|
+
setIsLoading(false);
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
[sdk, isInjected]
|
|
327
|
+
);
|
|
328
|
+
const refetch = (0, import_react4.useCallback)(
|
|
329
|
+
async () => {
|
|
330
|
+
if (!sdk || !isInjected) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
setIsLoading(true);
|
|
335
|
+
setError(null);
|
|
336
|
+
const [statusResult, supportedResult] = await Promise.all([
|
|
337
|
+
sdk.getAutoConfirmStatus(),
|
|
338
|
+
sdk.getSupportedAutoConfirmChains()
|
|
339
|
+
]);
|
|
340
|
+
setStatus(statusResult);
|
|
341
|
+
setSupportedChains(supportedResult);
|
|
342
|
+
} catch (err) {
|
|
343
|
+
const error2 = err instanceof Error ? err : new Error("Failed to fetch auto-confirm data");
|
|
344
|
+
setError(error2);
|
|
345
|
+
} finally {
|
|
346
|
+
setIsLoading(false);
|
|
347
|
+
}
|
|
348
|
+
},
|
|
349
|
+
[sdk, isInjected]
|
|
350
|
+
);
|
|
351
|
+
(0, import_react4.useEffect)(() => {
|
|
352
|
+
if (sdk && isInjected) {
|
|
353
|
+
refetch();
|
|
354
|
+
} else {
|
|
355
|
+
setStatus(null);
|
|
356
|
+
setSupportedChains(null);
|
|
357
|
+
setError(null);
|
|
358
|
+
}
|
|
359
|
+
}, [sdk, isInjected, refetch]);
|
|
360
|
+
return {
|
|
361
|
+
enable,
|
|
362
|
+
disable,
|
|
363
|
+
status,
|
|
364
|
+
supportedChains,
|
|
365
|
+
isLoading,
|
|
366
|
+
error,
|
|
367
|
+
refetch
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// src/hooks/useSolana.ts
|
|
372
|
+
var import_react5 = require("react");
|
|
373
|
+
function useSolana() {
|
|
374
|
+
const { sdk, isConnected } = usePhantom();
|
|
375
|
+
const solanaChain = (0, import_react5.useMemo)(() => {
|
|
376
|
+
if (!sdk || !isConnected)
|
|
377
|
+
return null;
|
|
378
|
+
try {
|
|
379
|
+
return sdk.solana;
|
|
380
|
+
} catch {
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
}, [sdk, isConnected]);
|
|
384
|
+
const signMessage = (0, import_react5.useCallback)(async (message) => {
|
|
385
|
+
if (!solanaChain)
|
|
386
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
387
|
+
return solanaChain.signMessage(message);
|
|
388
|
+
}, [solanaChain]);
|
|
389
|
+
const signTransaction = (0, import_react5.useCallback)(async (transaction) => {
|
|
390
|
+
if (!solanaChain)
|
|
391
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
392
|
+
return solanaChain.signTransaction(transaction);
|
|
393
|
+
}, [solanaChain]);
|
|
394
|
+
const signAndSendTransaction = (0, import_react5.useCallback)(async (transaction) => {
|
|
395
|
+
if (!solanaChain)
|
|
396
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
397
|
+
return solanaChain.signAndSendTransaction(transaction);
|
|
398
|
+
}, [solanaChain]);
|
|
399
|
+
const connect = (0, import_react5.useCallback)(async (options) => {
|
|
400
|
+
if (!solanaChain)
|
|
401
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
402
|
+
return solanaChain.connect(options);
|
|
403
|
+
}, [solanaChain]);
|
|
404
|
+
const disconnect = (0, import_react5.useCallback)(async () => {
|
|
405
|
+
if (!solanaChain)
|
|
406
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
407
|
+
return solanaChain.disconnect();
|
|
408
|
+
}, [solanaChain]);
|
|
409
|
+
const switchNetwork = (0, import_react5.useCallback)(async (network) => {
|
|
410
|
+
if (!solanaChain)
|
|
411
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
412
|
+
return solanaChain.switchNetwork(network);
|
|
413
|
+
}, [solanaChain]);
|
|
414
|
+
const getPublicKey = (0, import_react5.useCallback)(async () => {
|
|
415
|
+
if (!solanaChain)
|
|
416
|
+
return null;
|
|
417
|
+
return solanaChain.getPublicKey();
|
|
418
|
+
}, [solanaChain]);
|
|
419
|
+
return {
|
|
420
|
+
// Chain instance for advanced usage
|
|
421
|
+
solana: solanaChain,
|
|
422
|
+
// Convenient methods
|
|
423
|
+
signMessage,
|
|
424
|
+
signTransaction,
|
|
425
|
+
signAndSendTransaction,
|
|
426
|
+
connect,
|
|
427
|
+
disconnect,
|
|
428
|
+
switchNetwork,
|
|
429
|
+
getPublicKey,
|
|
430
|
+
// State
|
|
431
|
+
isAvailable: !!solanaChain,
|
|
432
|
+
isConnected: solanaChain?.isConnected() ?? false
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// src/hooks/useEthereum.ts
|
|
437
|
+
var import_react6 = require("react");
|
|
438
|
+
function useEthereum() {
|
|
439
|
+
const { sdk, isConnected } = usePhantom();
|
|
440
|
+
const ethereumChain = (0, import_react6.useMemo)(() => {
|
|
441
|
+
if (!sdk || !isConnected)
|
|
442
|
+
return null;
|
|
443
|
+
try {
|
|
444
|
+
return sdk.ethereum;
|
|
445
|
+
} catch {
|
|
446
|
+
return null;
|
|
447
|
+
}
|
|
448
|
+
}, [sdk, isConnected]);
|
|
449
|
+
const request = (0, import_react6.useCallback)(async (args) => {
|
|
450
|
+
if (!ethereumChain)
|
|
451
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
452
|
+
return ethereumChain.request(args);
|
|
453
|
+
}, [ethereumChain]);
|
|
454
|
+
const signPersonalMessage = (0, import_react6.useCallback)(async (message, address) => {
|
|
455
|
+
return request({
|
|
456
|
+
method: "personal_sign",
|
|
457
|
+
params: [message, address]
|
|
458
|
+
});
|
|
459
|
+
}, [request]);
|
|
460
|
+
const sendTransaction = (0, import_react6.useCallback)(async (transaction) => {
|
|
461
|
+
if (!ethereumChain)
|
|
462
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
463
|
+
return ethereumChain.sendTransaction(transaction);
|
|
464
|
+
}, [ethereumChain]);
|
|
465
|
+
const switchChain = (0, import_react6.useCallback)(async (chainId) => {
|
|
466
|
+
if (!ethereumChain)
|
|
467
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
468
|
+
return ethereumChain.switchChain(chainId);
|
|
469
|
+
}, [ethereumChain]);
|
|
470
|
+
const getChainId = (0, import_react6.useCallback)(async () => {
|
|
471
|
+
if (!ethereumChain)
|
|
472
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
473
|
+
return ethereumChain.getChainId();
|
|
474
|
+
}, [ethereumChain]);
|
|
475
|
+
const getAccounts = (0, import_react6.useCallback)(async () => {
|
|
476
|
+
if (!ethereumChain)
|
|
477
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
478
|
+
return ethereumChain.getAccounts();
|
|
479
|
+
}, [ethereumChain]);
|
|
480
|
+
const signMessage = (0, import_react6.useCallback)(async (message) => {
|
|
481
|
+
return request({
|
|
482
|
+
method: "eth_sign",
|
|
483
|
+
params: [await getAccounts().then((accounts) => accounts[0]), message]
|
|
484
|
+
});
|
|
485
|
+
}, [request, getAccounts]);
|
|
486
|
+
const signTypedData = (0, import_react6.useCallback)(async (typedData) => {
|
|
487
|
+
const accounts = await getAccounts();
|
|
488
|
+
return request({
|
|
489
|
+
method: "eth_signTypedData_v4",
|
|
490
|
+
params: [accounts[0], JSON.stringify(typedData)]
|
|
491
|
+
});
|
|
492
|
+
}, [request, getAccounts]);
|
|
493
|
+
return {
|
|
494
|
+
// Chain instance for advanced usage
|
|
495
|
+
ethereum: ethereumChain,
|
|
496
|
+
// Standard EIP-1193 interface
|
|
497
|
+
request,
|
|
498
|
+
// Convenient methods
|
|
499
|
+
signPersonalMessage,
|
|
500
|
+
signMessage,
|
|
501
|
+
signTypedData,
|
|
502
|
+
sendTransaction,
|
|
503
|
+
switchChain,
|
|
504
|
+
getChainId,
|
|
505
|
+
getAccounts,
|
|
506
|
+
// State
|
|
507
|
+
isAvailable: !!ethereumChain,
|
|
508
|
+
isConnected: ethereumChain?.isConnected() ?? false
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
|
|
339
512
|
// src/index.ts
|
|
340
|
-
var
|
|
513
|
+
var import_browser_sdk3 = require("@phantom/browser-sdk");
|