@phantom/react-sdk 1.0.5 → 1.0.7
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 +42 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +12 -2
- package/dist/index.mjs +21 -3
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1273,6 +1273,48 @@ function EthereumExample() {
|
|
|
1273
1273
|
}
|
|
1274
1274
|
```
|
|
1275
1275
|
|
|
1276
|
+
## Dapp-Sponsored Transactions (presignTransaction)
|
|
1277
|
+
|
|
1278
|
+
Pass `presignTransaction` directly to `signAndSendTransaction` for calls that need co-signing. Calls without it proceed normally — it is never applied globally.
|
|
1279
|
+
|
|
1280
|
+
> **Important:** Phantom embedded wallets do not accept pre-signed transactions. If your use case requires a second signer (e.g. your app as the fee payer), that signing must happen via this option, after Phantom has constructed and validated the transaction. This restriction does not apply to injected providers (e.g. the Phantom browser extension).
|
|
1281
|
+
|
|
1282
|
+
> **Note:** `presignTransaction` only fires for Solana transactions via the embedded provider. EVM transactions and injected providers are unaffected.
|
|
1283
|
+
|
|
1284
|
+
```tsx
|
|
1285
|
+
import { useSolana, base64urlDecode, base64urlEncode } from "@phantom/react-sdk";
|
|
1286
|
+
import { VersionedTransaction } from "@solana/web3.js";
|
|
1287
|
+
|
|
1288
|
+
function SendWithFeeSponsor() {
|
|
1289
|
+
const { solana } = useSolana();
|
|
1290
|
+
|
|
1291
|
+
const sendSponsored = async () => {
|
|
1292
|
+
// This call co-signs as fee payer.
|
|
1293
|
+
// presignTransaction should call your backend — never hold a fee payer keypair in frontend code.
|
|
1294
|
+
const result = await solana.signAndSendTransaction(transaction, {
|
|
1295
|
+
presignTransaction: async (tx, context) => {
|
|
1296
|
+
// Send the transaction to your backend for fee payer signing.
|
|
1297
|
+
// Your backend deserializes, partially signs, and returns the modified transaction.
|
|
1298
|
+
const response = await fetch("/api/presign", {
|
|
1299
|
+
method: "POST",
|
|
1300
|
+
body: JSON.stringify({ transaction: tx, networkId: context.networkId }),
|
|
1301
|
+
headers: { "Content-Type": "application/json" },
|
|
1302
|
+
});
|
|
1303
|
+
const { transaction: signedTx } = await response.json();
|
|
1304
|
+
return signedTx; // base64url-encoded, partially signed by the fee payer
|
|
1305
|
+
},
|
|
1306
|
+
});
|
|
1307
|
+
};
|
|
1308
|
+
|
|
1309
|
+
const sendNormal = async () => {
|
|
1310
|
+
// This call has no co-signer
|
|
1311
|
+
const result = await solana.signAndSendTransaction(transaction);
|
|
1312
|
+
};
|
|
1313
|
+
}
|
|
1314
|
+
```
|
|
1315
|
+
|
|
1316
|
+
> **Never hold a fee payer keypair in frontend code.** The `presignTransaction` callback runs in the browser — use it to call your own backend, which holds the keypair securely and returns the partially-signed transaction.
|
|
1317
|
+
|
|
1276
1318
|
## Hooks Reference
|
|
1277
1319
|
|
|
1278
1320
|
Quick reference of all available hooks:
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import * as _phantom_browser_sdk from '@phantom/browser-sdk';
|
|
4
4
|
import { BrowserSDKConfig, DebugConfig, AuthOptions, BrowserSDK, WalletAddress, ConnectResult, AuthProviderType, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult, InjectedWalletInfo, AddressType } from '@phantom/browser-sdk';
|
|
5
|
-
export { AddressType, AuthOptions, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult, ConnectErrorEventData, ConnectEventData, ConnectStartEventData, DebugLevel, DebugMessage, DisconnectEventData, EmbeddedProviderEvent, EmbeddedProviderEventMap, EventCallback, InjectedWalletId, InjectedWalletInfo, NetworkId, SignedTransaction, WalletAddress, debug, isMobileDevice } from '@phantom/browser-sdk';
|
|
5
|
+
export { AddressType, AuthOptions, AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult, ConnectErrorEventData, ConnectEventData, ConnectStartEventData, DebugLevel, DebugMessage, DisconnectEventData, EmbeddedProviderEvent, EmbeddedProviderEventMap, EventCallback, InjectedWalletId, InjectedWalletInfo, NetworkId, SignedTransaction, WalletAddress, base64urlDecode, base64urlEncode, debug, isMobileDevice } from '@phantom/browser-sdk';
|
|
6
6
|
import { PhantomTheme } from '@phantom/wallet-sdk-ui';
|
|
7
7
|
export { ComputedPhantomTheme, HexColor, PhantomTheme, darkTheme, lightTheme, mergeTheme, useTheme } from '@phantom/wallet-sdk-ui';
|
|
8
8
|
import { ISolanaChain, IEthereumChain } from '@phantom/chain-interfaces';
|
package/dist/index.js
CHANGED
|
@@ -36,6 +36,8 @@ __export(src_exports, {
|
|
|
36
36
|
DebugLevel: () => import_browser_sdk8.DebugLevel,
|
|
37
37
|
NetworkId: () => import_browser_sdk8.NetworkId,
|
|
38
38
|
PhantomProvider: () => PhantomProvider,
|
|
39
|
+
base64urlDecode: () => import_browser_sdk8.base64urlDecode,
|
|
40
|
+
base64urlEncode: () => import_browser_sdk8.base64urlEncode,
|
|
39
41
|
darkTheme: () => import_wallet_sdk_ui10.darkTheme,
|
|
40
42
|
debug: () => import_browser_sdk8.debug,
|
|
41
43
|
isMobileDevice: () => import_browser_sdk8.isMobileDevice,
|
|
@@ -842,8 +844,16 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
842
844
|
console.error("Error connecting:", err);
|
|
843
845
|
try {
|
|
844
846
|
await sdk.disconnect();
|
|
845
|
-
} catch (
|
|
846
|
-
console.error("Error disconnecting:",
|
|
847
|
+
} catch (disconnectErr) {
|
|
848
|
+
console.error("Error disconnecting after connect failure:", disconnectErr);
|
|
849
|
+
setIsConnected(false);
|
|
850
|
+
setIsConnecting(false);
|
|
851
|
+
setAddresses([]);
|
|
852
|
+
setUser(null);
|
|
853
|
+
setErrors((prev) => ({
|
|
854
|
+
...prev,
|
|
855
|
+
connect: err instanceof Error ? err : new Error("Failed to retrieve addresses after connect")
|
|
856
|
+
}));
|
|
847
857
|
}
|
|
848
858
|
}
|
|
849
859
|
};
|
package/dist/index.mjs
CHANGED
|
@@ -793,8 +793,16 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
793
793
|
console.error("Error connecting:", err);
|
|
794
794
|
try {
|
|
795
795
|
await sdk.disconnect();
|
|
796
|
-
} catch (
|
|
797
|
-
console.error("Error disconnecting:",
|
|
796
|
+
} catch (disconnectErr) {
|
|
797
|
+
console.error("Error disconnecting after connect failure:", disconnectErr);
|
|
798
|
+
setIsConnected(false);
|
|
799
|
+
setIsConnecting(false);
|
|
800
|
+
setAddresses([]);
|
|
801
|
+
setUser(null);
|
|
802
|
+
setErrors((prev) => ({
|
|
803
|
+
...prev,
|
|
804
|
+
connect: err instanceof Error ? err : new Error("Failed to retrieve addresses after connect")
|
|
805
|
+
}));
|
|
798
806
|
}
|
|
799
807
|
}
|
|
800
808
|
};
|
|
@@ -1138,7 +1146,15 @@ function ConnectBox({ maxWidth = "350px", transparent = false, appIcon, appName
|
|
|
1138
1146
|
|
|
1139
1147
|
// src/index.ts
|
|
1140
1148
|
import { darkTheme as darkTheme2, lightTheme, mergeTheme as mergeTheme2 } from "@phantom/wallet-sdk-ui";
|
|
1141
|
-
import {
|
|
1149
|
+
import {
|
|
1150
|
+
NetworkId,
|
|
1151
|
+
AddressType as AddressType3,
|
|
1152
|
+
DebugLevel,
|
|
1153
|
+
debug,
|
|
1154
|
+
isMobileDevice as isMobileDevice3,
|
|
1155
|
+
base64urlEncode,
|
|
1156
|
+
base64urlDecode
|
|
1157
|
+
} from "@phantom/browser-sdk";
|
|
1142
1158
|
export {
|
|
1143
1159
|
AddressType3 as AddressType,
|
|
1144
1160
|
ConnectBox,
|
|
@@ -1146,6 +1162,8 @@ export {
|
|
|
1146
1162
|
DebugLevel,
|
|
1147
1163
|
NetworkId,
|
|
1148
1164
|
PhantomProvider,
|
|
1165
|
+
base64urlDecode,
|
|
1166
|
+
base64urlEncode,
|
|
1149
1167
|
darkTheme2 as darkTheme,
|
|
1150
1168
|
debug,
|
|
1151
1169
|
isMobileDevice3 as isMobileDevice,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/react-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/phantom/phantom-connect-sdk",
|
|
@@ -31,10 +31,10 @@
|
|
|
31
31
|
"prettier": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@phantom/browser-sdk": "^1.0.
|
|
35
|
-
"@phantom/chain-interfaces": "^1.0.
|
|
36
|
-
"@phantom/constants": "^1.0.
|
|
37
|
-
"@phantom/wallet-sdk-ui": "^1.0.
|
|
34
|
+
"@phantom/browser-sdk": "^1.0.7",
|
|
35
|
+
"@phantom/chain-interfaces": "^1.0.7",
|
|
36
|
+
"@phantom/constants": "^1.0.7",
|
|
37
|
+
"@phantom/wallet-sdk-ui": "^1.0.7"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@testing-library/dom": "^10.4.0",
|