@phantom/react-sdk 1.0.0-beta.1 → 1.0.0-beta.2

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 CHANGED
@@ -470,6 +470,16 @@ function EthereumOperations() {
470
470
  console.log("Typed data signature:", signature);
471
471
  };
472
472
 
473
+ const signTransaction = async () => {
474
+ const signedTx = await ethereum.signTransaction({
475
+ to: "0x742d35Cc6634C0532925a3b8D4C8db86fB5C4A7E",
476
+ value: "1000000000000000000", // 1 ETH in wei
477
+ gas: "21000",
478
+ });
479
+ console.log("Transaction signed:", signedTx);
480
+ // Transaction is signed but not sent - you can broadcast it later
481
+ };
482
+
473
483
  const sendTransaction = async () => {
474
484
  const result = await ethereum.sendTransaction({
475
485
  to: "0x742d35Cc6634C0532925a3b8D4C8db86fB5C4A7E",
@@ -487,7 +497,8 @@ function EthereumOperations() {
487
497
  <div>
488
498
  <button onClick={signPersonalMessage}>Sign Personal Message</button>
489
499
  <button onClick={signTypedData}>Sign Typed Data</button>
490
- <button onClick={sendTransaction}>Send Transaction</button>
500
+ <button onClick={signTransaction}>Sign Transaction</button>
501
+ <button onClick={sendTransaction}>Sign & Send Transaction</button>
491
502
  <button onClick={switchChain}>Switch to Polygon</button>
492
503
  <p>Connected: {ethereum.isConnected ? "Yes" : "No"}</p>
493
504
  </div>
@@ -500,7 +511,8 @@ function EthereumOperations() {
500
511
  - `request(args)` - EIP-1193 requests
501
512
  - `signPersonalMessage(message, address)` - Sign personal message
502
513
  - `signTypedData(typedData)` - Sign EIP-712 typed data
503
- - `sendTransaction(transaction)` - Send transaction
514
+ - `signTransaction(transaction)` - Sign transaction without sending
515
+ - `sendTransaction(transaction)` - Sign and send transaction
504
516
  - `switchChain(chainId)` - Switch chains
505
517
  - `getChainId()` - Get current chain ID
506
518
  - `getAccounts()` - Get connected accounts
package/dist/index.d.ts CHANGED
@@ -109,6 +109,7 @@ declare function useEthereum(): {
109
109
  }) => Promise<T>;
110
110
  signPersonalMessage: (message: string, address: string) => Promise<string>;
111
111
  signMessage: (message: string) => Promise<string>;
112
+ signTransaction: (transaction: EthTransactionRequest) => Promise<string>;
112
113
  signTypedData: (typedData: any) => Promise<string>;
113
114
  sendTransaction: (transaction: EthTransactionRequest) => Promise<string>;
114
115
  switchChain: (chainId: number) => Promise<void>;
package/dist/index.js CHANGED
@@ -356,6 +356,13 @@ function useAutoConfirm() {
356
356
  var import_react5 = require("react");
357
357
  function useSolana() {
358
358
  const { sdk, isConnected } = usePhantom();
359
+ const getSolanaChain = (0, import_react5.useCallback)(() => {
360
+ if (!sdk)
361
+ throw new Error("Phantom SDK not initialized.");
362
+ if (!sdk.isConnected())
363
+ throw new Error("Phantom SDK not connected. Call connect() first.");
364
+ return sdk.solana;
365
+ }, [sdk]);
359
366
  const solanaChain = (0, import_react5.useMemo)(() => {
360
367
  if (!sdk || !isConnected)
361
368
  return null;
@@ -367,54 +374,48 @@ function useSolana() {
367
374
  }, [sdk, isConnected]);
368
375
  const signMessage = (0, import_react5.useCallback)(
369
376
  async (message) => {
370
- if (!solanaChain)
371
- throw new Error("Solana chain not available. Ensure SDK is connected.");
372
- return solanaChain.signMessage(message);
377
+ const chain = getSolanaChain();
378
+ return chain.signMessage(message);
373
379
  },
374
- [solanaChain]
380
+ [getSolanaChain]
375
381
  );
376
382
  const signTransaction = (0, import_react5.useCallback)(
377
383
  async (transaction) => {
378
- if (!solanaChain)
379
- throw new Error("Solana chain not available. Ensure SDK is connected.");
380
- return solanaChain.signTransaction(transaction);
384
+ const chain = getSolanaChain();
385
+ return chain.signTransaction(transaction);
381
386
  },
382
- [solanaChain]
387
+ [getSolanaChain]
383
388
  );
384
389
  const signAndSendTransaction = (0, import_react5.useCallback)(
385
390
  async (transaction) => {
386
- if (!solanaChain)
387
- throw new Error("Solana chain not available. Ensure SDK is connected.");
388
- return solanaChain.signAndSendTransaction(transaction);
391
+ const chain = getSolanaChain();
392
+ return chain.signAndSendTransaction(transaction);
389
393
  },
390
- [solanaChain]
394
+ [getSolanaChain]
391
395
  );
392
396
  const connect = (0, import_react5.useCallback)(
393
397
  async (options) => {
394
- if (!solanaChain)
395
- throw new Error("Solana chain not available. Ensure SDK is connected.");
396
- return solanaChain.connect(options);
398
+ const chain = getSolanaChain();
399
+ return chain.connect(options);
397
400
  },
398
- [solanaChain]
401
+ [getSolanaChain]
399
402
  );
400
403
  const disconnect = (0, import_react5.useCallback)(async () => {
401
- if (!solanaChain)
402
- throw new Error("Solana chain not available. Ensure SDK is connected.");
403
- return solanaChain.disconnect();
404
- }, [solanaChain]);
404
+ const chain = getSolanaChain();
405
+ return chain.disconnect();
406
+ }, [getSolanaChain]);
405
407
  const switchNetwork = (0, import_react5.useCallback)(
406
408
  async (network) => {
407
- if (!solanaChain)
408
- throw new Error("Solana chain not available. Ensure SDK is connected.");
409
- return solanaChain.switchNetwork?.(network);
409
+ const chain = getSolanaChain();
410
+ return chain.switchNetwork?.(network);
410
411
  },
411
- [solanaChain]
412
+ [getSolanaChain]
412
413
  );
413
414
  const getPublicKey = (0, import_react5.useCallback)(async () => {
414
- if (!solanaChain)
415
+ if (!sdk || !sdk.isConnected())
415
416
  return null;
416
- return solanaChain.getPublicKey();
417
- }, [solanaChain]);
417
+ return sdk.solana.getPublicKey();
418
+ }, [sdk]);
418
419
  return {
419
420
  // Chain instance for advanced usage
420
421
  solana: solanaChain,
@@ -436,6 +437,13 @@ function useSolana() {
436
437
  var import_react6 = require("react");
437
438
  function useEthereum() {
438
439
  const { sdk, isConnected } = usePhantom();
440
+ const getEthereumChain = (0, import_react6.useCallback)(() => {
441
+ if (!sdk)
442
+ throw new Error("Phantom SDK not initialized.");
443
+ if (!sdk.isConnected())
444
+ throw new Error("Phantom SDK not connected. Call connect() first.");
445
+ return sdk.ethereum;
446
+ }, [sdk]);
439
447
  const ethereumChain = (0, import_react6.useMemo)(() => {
440
448
  if (!sdk || !isConnected)
441
449
  return null;
@@ -447,11 +455,10 @@ function useEthereum() {
447
455
  }, [sdk, isConnected]);
448
456
  const request = (0, import_react6.useCallback)(
449
457
  async (args) => {
450
- if (!ethereumChain)
451
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
452
- return ethereumChain.request(args);
458
+ const chain = getEthereumChain();
459
+ return chain.request(args);
453
460
  },
454
- [ethereumChain]
461
+ [getEthereumChain]
455
462
  );
456
463
  const signPersonalMessage = (0, import_react6.useCallback)(
457
464
  async (message, address) => {
@@ -462,32 +469,35 @@ function useEthereum() {
462
469
  },
463
470
  [request]
464
471
  );
472
+ const signTransaction = (0, import_react6.useCallback)(
473
+ async (transaction) => {
474
+ const chain = getEthereumChain();
475
+ return chain.signTransaction(transaction);
476
+ },
477
+ [getEthereumChain]
478
+ );
465
479
  const sendTransaction = (0, import_react6.useCallback)(
466
480
  async (transaction) => {
467
- if (!ethereumChain)
468
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
469
- return ethereumChain.sendTransaction(transaction);
481
+ const chain = getEthereumChain();
482
+ return chain.sendTransaction(transaction);
470
483
  },
471
- [ethereumChain]
484
+ [getEthereumChain]
472
485
  );
473
486
  const switchChain = (0, import_react6.useCallback)(
474
487
  async (chainId) => {
475
- if (!ethereumChain)
476
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
477
- return ethereumChain.switchChain(chainId);
488
+ const chain = getEthereumChain();
489
+ return chain.switchChain(chainId);
478
490
  },
479
- [ethereumChain]
491
+ [getEthereumChain]
480
492
  );
481
493
  const getChainId = (0, import_react6.useCallback)(async () => {
482
- if (!ethereumChain)
483
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
484
- return ethereumChain.getChainId();
485
- }, [ethereumChain]);
494
+ const chain = getEthereumChain();
495
+ return chain.getChainId();
496
+ }, [getEthereumChain]);
486
497
  const getAccounts = (0, import_react6.useCallback)(async () => {
487
- if (!ethereumChain)
488
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
489
- return ethereumChain.getAccounts();
490
- }, [ethereumChain]);
498
+ const chain = getEthereumChain();
499
+ return chain.getAccounts();
500
+ }, [getEthereumChain]);
491
501
  const signMessage = (0, import_react6.useCallback)(
492
502
  async (message) => {
493
503
  return request({
@@ -515,6 +525,7 @@ function useEthereum() {
515
525
  // Convenient methods
516
526
  signPersonalMessage,
517
527
  signMessage,
528
+ signTransaction,
518
529
  signTypedData,
519
530
  sendTransaction,
520
531
  switchChain,
package/dist/index.mjs CHANGED
@@ -308,6 +308,13 @@ function useAutoConfirm() {
308
308
  import { useCallback as useCallback4, useMemo as useMemo2 } from "react";
309
309
  function useSolana() {
310
310
  const { sdk, isConnected } = usePhantom();
311
+ const getSolanaChain = useCallback4(() => {
312
+ if (!sdk)
313
+ throw new Error("Phantom SDK not initialized.");
314
+ if (!sdk.isConnected())
315
+ throw new Error("Phantom SDK not connected. Call connect() first.");
316
+ return sdk.solana;
317
+ }, [sdk]);
311
318
  const solanaChain = useMemo2(() => {
312
319
  if (!sdk || !isConnected)
313
320
  return null;
@@ -319,54 +326,48 @@ function useSolana() {
319
326
  }, [sdk, isConnected]);
320
327
  const signMessage = useCallback4(
321
328
  async (message) => {
322
- if (!solanaChain)
323
- throw new Error("Solana chain not available. Ensure SDK is connected.");
324
- return solanaChain.signMessage(message);
329
+ const chain = getSolanaChain();
330
+ return chain.signMessage(message);
325
331
  },
326
- [solanaChain]
332
+ [getSolanaChain]
327
333
  );
328
334
  const signTransaction = useCallback4(
329
335
  async (transaction) => {
330
- if (!solanaChain)
331
- throw new Error("Solana chain not available. Ensure SDK is connected.");
332
- return solanaChain.signTransaction(transaction);
336
+ const chain = getSolanaChain();
337
+ return chain.signTransaction(transaction);
333
338
  },
334
- [solanaChain]
339
+ [getSolanaChain]
335
340
  );
336
341
  const signAndSendTransaction = useCallback4(
337
342
  async (transaction) => {
338
- if (!solanaChain)
339
- throw new Error("Solana chain not available. Ensure SDK is connected.");
340
- return solanaChain.signAndSendTransaction(transaction);
343
+ const chain = getSolanaChain();
344
+ return chain.signAndSendTransaction(transaction);
341
345
  },
342
- [solanaChain]
346
+ [getSolanaChain]
343
347
  );
344
348
  const connect = useCallback4(
345
349
  async (options) => {
346
- if (!solanaChain)
347
- throw new Error("Solana chain not available. Ensure SDK is connected.");
348
- return solanaChain.connect(options);
350
+ const chain = getSolanaChain();
351
+ return chain.connect(options);
349
352
  },
350
- [solanaChain]
353
+ [getSolanaChain]
351
354
  );
352
355
  const disconnect = useCallback4(async () => {
353
- if (!solanaChain)
354
- throw new Error("Solana chain not available. Ensure SDK is connected.");
355
- return solanaChain.disconnect();
356
- }, [solanaChain]);
356
+ const chain = getSolanaChain();
357
+ return chain.disconnect();
358
+ }, [getSolanaChain]);
357
359
  const switchNetwork = useCallback4(
358
360
  async (network) => {
359
- if (!solanaChain)
360
- throw new Error("Solana chain not available. Ensure SDK is connected.");
361
- return solanaChain.switchNetwork?.(network);
361
+ const chain = getSolanaChain();
362
+ return chain.switchNetwork?.(network);
362
363
  },
363
- [solanaChain]
364
+ [getSolanaChain]
364
365
  );
365
366
  const getPublicKey = useCallback4(async () => {
366
- if (!solanaChain)
367
+ if (!sdk || !sdk.isConnected())
367
368
  return null;
368
- return solanaChain.getPublicKey();
369
- }, [solanaChain]);
369
+ return sdk.solana.getPublicKey();
370
+ }, [sdk]);
370
371
  return {
371
372
  // Chain instance for advanced usage
372
373
  solana: solanaChain,
@@ -388,6 +389,13 @@ function useSolana() {
388
389
  import { useCallback as useCallback5, useMemo as useMemo3 } from "react";
389
390
  function useEthereum() {
390
391
  const { sdk, isConnected } = usePhantom();
392
+ const getEthereumChain = useCallback5(() => {
393
+ if (!sdk)
394
+ throw new Error("Phantom SDK not initialized.");
395
+ if (!sdk.isConnected())
396
+ throw new Error("Phantom SDK not connected. Call connect() first.");
397
+ return sdk.ethereum;
398
+ }, [sdk]);
391
399
  const ethereumChain = useMemo3(() => {
392
400
  if (!sdk || !isConnected)
393
401
  return null;
@@ -399,11 +407,10 @@ function useEthereum() {
399
407
  }, [sdk, isConnected]);
400
408
  const request = useCallback5(
401
409
  async (args) => {
402
- if (!ethereumChain)
403
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
404
- return ethereumChain.request(args);
410
+ const chain = getEthereumChain();
411
+ return chain.request(args);
405
412
  },
406
- [ethereumChain]
413
+ [getEthereumChain]
407
414
  );
408
415
  const signPersonalMessage = useCallback5(
409
416
  async (message, address) => {
@@ -414,32 +421,35 @@ function useEthereum() {
414
421
  },
415
422
  [request]
416
423
  );
424
+ const signTransaction = useCallback5(
425
+ async (transaction) => {
426
+ const chain = getEthereumChain();
427
+ return chain.signTransaction(transaction);
428
+ },
429
+ [getEthereumChain]
430
+ );
417
431
  const sendTransaction = useCallback5(
418
432
  async (transaction) => {
419
- if (!ethereumChain)
420
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
421
- return ethereumChain.sendTransaction(transaction);
433
+ const chain = getEthereumChain();
434
+ return chain.sendTransaction(transaction);
422
435
  },
423
- [ethereumChain]
436
+ [getEthereumChain]
424
437
  );
425
438
  const switchChain = useCallback5(
426
439
  async (chainId) => {
427
- if (!ethereumChain)
428
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
429
- return ethereumChain.switchChain(chainId);
440
+ const chain = getEthereumChain();
441
+ return chain.switchChain(chainId);
430
442
  },
431
- [ethereumChain]
443
+ [getEthereumChain]
432
444
  );
433
445
  const getChainId = useCallback5(async () => {
434
- if (!ethereumChain)
435
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
436
- return ethereumChain.getChainId();
437
- }, [ethereumChain]);
446
+ const chain = getEthereumChain();
447
+ return chain.getChainId();
448
+ }, [getEthereumChain]);
438
449
  const getAccounts = useCallback5(async () => {
439
- if (!ethereumChain)
440
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
441
- return ethereumChain.getAccounts();
442
- }, [ethereumChain]);
450
+ const chain = getEthereumChain();
451
+ return chain.getAccounts();
452
+ }, [getEthereumChain]);
443
453
  const signMessage = useCallback5(
444
454
  async (message) => {
445
455
  return request({
@@ -467,6 +477,7 @@ function useEthereum() {
467
477
  // Convenient methods
468
478
  signPersonalMessage,
469
479
  signMessage,
480
+ signTransaction,
470
481
  signTypedData,
471
482
  sendTransaction,
472
483
  switchChain,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/react-sdk",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.mjs",
6
6
  "types": "dist/index.d.ts",
@@ -26,9 +26,9 @@
26
26
  "prettier": "prettier --write \"src/**/*.{ts,tsx}\""
27
27
  },
28
28
  "dependencies": {
29
- "@phantom/browser-sdk": "^1.0.0-beta.1",
30
- "@phantom/chains": "^1.0.0-beta.1",
31
- "@phantom/constants": "^1.0.0-beta.1"
29
+ "@phantom/browser-sdk": "^1.0.0-beta.2",
30
+ "@phantom/chains": "^1.0.0-beta.2",
31
+ "@phantom/constants": "^1.0.0-beta.2"
32
32
  },
33
33
  "devDependencies": {
34
34
  "@testing-library/dom": "^10.4.0",