@phantom/react-sdk 1.0.0-beta.21 → 1.0.0-beta.24
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 +372 -52
- package/dist/index.d.ts +47 -17
- package/dist/index.js +894 -199
- package/dist/index.mjs +903 -196
- package/package.json +13 -6
package/README.md
CHANGED
|
@@ -41,7 +41,7 @@ function App() {
|
|
|
41
41
|
return (
|
|
42
42
|
<PhantomProvider
|
|
43
43
|
config={{
|
|
44
|
-
|
|
44
|
+
providers: ["injected"], // Only allow Phantom browser extension
|
|
45
45
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
46
46
|
}}
|
|
47
47
|
>
|
|
@@ -83,7 +83,7 @@ function WalletComponent() {
|
|
|
83
83
|
}
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
-
###
|
|
86
|
+
### Multiple Authentication Methods
|
|
87
87
|
|
|
88
88
|
```tsx
|
|
89
89
|
import { PhantomProvider } from "@phantom/react-sdk";
|
|
@@ -93,8 +93,8 @@ function App() {
|
|
|
93
93
|
return (
|
|
94
94
|
<PhantomProvider
|
|
95
95
|
config={{
|
|
96
|
-
|
|
97
|
-
appId: "your-app-id", // Get your app ID from phantom.com/portal
|
|
96
|
+
providers: ["google", "apple", "phantom", "injected"], // Allow all auth methods
|
|
97
|
+
appId: "your-app-id", // Get your app ID from phantom.com/portal (required for embedded providers)
|
|
98
98
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
99
99
|
}}
|
|
100
100
|
>
|
|
@@ -104,6 +104,195 @@ function App() {
|
|
|
104
104
|
}
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
+
## Connection Modal
|
|
108
|
+
|
|
109
|
+
The SDK includes a built-in connection modal UI that provides a user-friendly interface for connecting to Phantom. The modal supports multiple connection methods (Google, Apple, Phantom Login, browser extension) and handles all connection logic automatically.
|
|
110
|
+
|
|
111
|
+
### Using the Modal
|
|
112
|
+
|
|
113
|
+
To use the modal, pass a `theme` prop to `PhantomProvider` and use the `useModal()` hook to control visibility:
|
|
114
|
+
|
|
115
|
+
```tsx
|
|
116
|
+
import { PhantomProvider, useModal, darkTheme, usePhantom } from "@phantom/react-sdk";
|
|
117
|
+
import { AddressType } from "@phantom/browser-sdk";
|
|
118
|
+
|
|
119
|
+
function App() {
|
|
120
|
+
return (
|
|
121
|
+
<PhantomProvider
|
|
122
|
+
config={{
|
|
123
|
+
providers: ["google", "apple", "phantom", "injected"],
|
|
124
|
+
appId: "your-app-id",
|
|
125
|
+
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
126
|
+
}}
|
|
127
|
+
theme={darkTheme}
|
|
128
|
+
appIcon="https://your-app.com/icon.png"
|
|
129
|
+
appName="Your App Name"
|
|
130
|
+
>
|
|
131
|
+
<WalletComponent />
|
|
132
|
+
</PhantomProvider>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function WalletComponent() {
|
|
137
|
+
const { open, close, isOpened } = useModal();
|
|
138
|
+
const { isConnected, user } = usePhantom();
|
|
139
|
+
|
|
140
|
+
if (isConnected) {
|
|
141
|
+
return (
|
|
142
|
+
<div>
|
|
143
|
+
<p>Connected as {user?.email || "Unknown"}</p>
|
|
144
|
+
</div>
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return <button onClick={open}>Connect Wallet</button>;
|
|
149
|
+
}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
**Modal Features:**
|
|
153
|
+
|
|
154
|
+
- **Multiple Auth Providers**: Google, Apple, Phantom Login, browser extension
|
|
155
|
+
- **Automatic Provider Detection**: Shows browser extension option when Phantom is installed
|
|
156
|
+
- **Mobile Support**: Displays deeplink option for Phantom mobile app on mobile devices
|
|
157
|
+
- **Error Handling**: Clear error messages displayed in the modal
|
|
158
|
+
- **Loading States**: Visual feedback during connection attempts
|
|
159
|
+
- **Responsive Design**: Optimized for both mobile and desktop
|
|
160
|
+
|
|
161
|
+
### useModal Hook
|
|
162
|
+
|
|
163
|
+
Control the connection modal visibility:
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
import { useModal } from "@phantom/react-sdk";
|
|
167
|
+
|
|
168
|
+
function ConnectButton() {
|
|
169
|
+
const { open, close, isOpened } = useModal();
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<div>
|
|
173
|
+
<button onClick={open}>Open Modal</button>
|
|
174
|
+
<button onClick={close}>Close Modal</button>
|
|
175
|
+
<p>Modal is {isOpened ? "open" : "closed"}</p>
|
|
176
|
+
</div>
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Returns:**
|
|
182
|
+
|
|
183
|
+
- `open()` - Function to open the modal
|
|
184
|
+
- `close()` - Function to close the modal
|
|
185
|
+
- `isOpened` - Boolean indicating if modal is currently visible
|
|
186
|
+
|
|
187
|
+
### ConnectButton Component
|
|
188
|
+
|
|
189
|
+
A ready-to-use button component that handles the complete connection flow. When disconnected, it shows a "Connect Wallet" button that opens the connection modal. When connected, it displays the truncated wallet address and opens the wallet management modal on click.
|
|
190
|
+
|
|
191
|
+
```tsx
|
|
192
|
+
import { ConnectButton, AddressType } from "@phantom/react-sdk";
|
|
193
|
+
|
|
194
|
+
function Header() {
|
|
195
|
+
return (
|
|
196
|
+
<div>
|
|
197
|
+
{/* Default: Shows first available address */}
|
|
198
|
+
<ConnectButton />
|
|
199
|
+
|
|
200
|
+
{/* Show specific address type */}
|
|
201
|
+
<ConnectButton addressType={AddressType.solana} />
|
|
202
|
+
<ConnectButton addressType={AddressType.ethereum} />
|
|
203
|
+
|
|
204
|
+
{/* Full width button */}
|
|
205
|
+
<ConnectButton fullWidth />
|
|
206
|
+
</div>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
**Props:**
|
|
212
|
+
|
|
213
|
+
- `addressType?: AddressType` - Specify which address type to display when connected (e.g., `AddressType.solana`, `AddressType.ethereum`). If not specified, shows the first available address.
|
|
214
|
+
- `fullWidth?: boolean` - Whether the button should take full width of its container. Default: `false`
|
|
215
|
+
|
|
216
|
+
**Features:**
|
|
217
|
+
|
|
218
|
+
- **When disconnected**: Opens connection modal with auth provider options (Google, Apple, Phantom Login, browser extension)
|
|
219
|
+
- **When connected**: Displays truncated address (e.g., "5Gv8r2...k3Hn") and opens wallet management modal on click
|
|
220
|
+
- **Wallet modal**: Shows all connected addresses and provides a disconnect button
|
|
221
|
+
- Uses theme styling for consistent appearance
|
|
222
|
+
- Fully clickable in both states
|
|
223
|
+
|
|
224
|
+
## Theming
|
|
225
|
+
|
|
226
|
+
Customize the modal appearance by passing a theme object to the `PhantomProvider`. The SDK includes two built-in themes: `darkTheme` (default) and `lightTheme`.
|
|
227
|
+
|
|
228
|
+
### Using Built-in Themes
|
|
229
|
+
|
|
230
|
+
```tsx
|
|
231
|
+
import { PhantomProvider, darkTheme, lightTheme } from "@phantom/react-sdk";
|
|
232
|
+
|
|
233
|
+
// Use dark theme (default)
|
|
234
|
+
<PhantomProvider config={config} theme={darkTheme}>
|
|
235
|
+
<App />
|
|
236
|
+
</PhantomProvider>
|
|
237
|
+
|
|
238
|
+
// Use light theme
|
|
239
|
+
<PhantomProvider config={config} theme={lightTheme}>
|
|
240
|
+
<App />
|
|
241
|
+
</PhantomProvider>
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Custom Theme
|
|
245
|
+
|
|
246
|
+
You can pass a partial theme object to customize specific properties:
|
|
247
|
+
|
|
248
|
+
```tsx
|
|
249
|
+
import { PhantomProvider } from "@phantom/react-sdk";
|
|
250
|
+
|
|
251
|
+
const customTheme = {
|
|
252
|
+
background: "#1a1a1a",
|
|
253
|
+
text: "#ffffff",
|
|
254
|
+
secondary: "#98979C",
|
|
255
|
+
brand: "#ab9ff2",
|
|
256
|
+
error: "#ff4444",
|
|
257
|
+
success: "#00ff00",
|
|
258
|
+
borderRadius: "16px",
|
|
259
|
+
overlay: "rgba(0, 0, 0, 0.8)",
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
<PhantomProvider config={config} theme={customTheme} appIcon="https://your-app.com/icon.png" appName="Your App">
|
|
263
|
+
<App />
|
|
264
|
+
</PhantomProvider>;
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Theme Properties
|
|
268
|
+
|
|
269
|
+
| Property | Type | Description |
|
|
270
|
+
| -------------- | -------- | --------------------------------------------------------- |
|
|
271
|
+
| `background` | `string` | Background color for modal |
|
|
272
|
+
| `text` | `string` | Primary text color |
|
|
273
|
+
| `secondary` | `string` | Secondary color for text, borders, dividers (must be hex) |
|
|
274
|
+
| `brand` | `string` | Brand/primary action color |
|
|
275
|
+
| `error` | `string` | Error state color |
|
|
276
|
+
| `success` | `string` | Success state color |
|
|
277
|
+
| `borderRadius` | `string` | Border radius for buttons and modal |
|
|
278
|
+
| `overlay` | `string` | Overlay background color (with opacity) |
|
|
279
|
+
|
|
280
|
+
**Note:** The `secondary` color must be a hex color value (e.g., `#98979C`) as it's used to derive auxiliary colors with opacity.
|
|
281
|
+
|
|
282
|
+
### Accessing Theme in Custom Components
|
|
283
|
+
|
|
284
|
+
If you need to access the current theme in your own components, use the `useTheme()` hook:
|
|
285
|
+
|
|
286
|
+
```tsx
|
|
287
|
+
import { useTheme } from "@phantom/react-sdk";
|
|
288
|
+
|
|
289
|
+
function CustomComponent() {
|
|
290
|
+
const theme = useTheme();
|
|
291
|
+
|
|
292
|
+
return <div style={{ backgroundColor: theme.background, color: theme.text }}>Themed content</div>;
|
|
293
|
+
}
|
|
294
|
+
```
|
|
295
|
+
|
|
107
296
|
## Connection Flow
|
|
108
297
|
|
|
109
298
|
The React SDK follows a clear connection pattern:
|
|
@@ -173,16 +362,58 @@ await connect({
|
|
|
173
362
|
});
|
|
174
363
|
```
|
|
175
364
|
|
|
176
|
-
##
|
|
365
|
+
## SDK Initialization
|
|
366
|
+
|
|
367
|
+
The SDK provides an `isLoading` state to track when initialization and autoconnect are in progress. This is useful for showing loading states before your app is ready.
|
|
368
|
+
|
|
369
|
+
```tsx
|
|
370
|
+
import { useConnect, usePhantom } from "@phantom/react-sdk";
|
|
371
|
+
|
|
372
|
+
function App() {
|
|
373
|
+
const { isLoading } = usePhantom();
|
|
374
|
+
const { connect } = useConnect();
|
|
375
|
+
|
|
376
|
+
// Show loading state while SDK initializes
|
|
377
|
+
if (isLoading) {
|
|
378
|
+
return (
|
|
379
|
+
<div>
|
|
380
|
+
<h1>Initializing Phantom SDK...</h1>
|
|
381
|
+
<p>Please wait...</p>
|
|
382
|
+
</div>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// SDK is ready
|
|
387
|
+
return (
|
|
388
|
+
<div>
|
|
389
|
+
<h1>Welcome!</h1>
|
|
390
|
+
<button onClick={() => connect({ provider: "injected" })}>Connect Wallet</button>
|
|
391
|
+
</div>
|
|
392
|
+
);
|
|
393
|
+
}
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
## Authentication Providers
|
|
177
397
|
|
|
178
|
-
|
|
398
|
+
The SDK supports multiple authentication providers that you configure via the `providers` array:
|
|
179
399
|
|
|
180
|
-
|
|
400
|
+
### Available Providers
|
|
401
|
+
|
|
402
|
+
- **`"injected"`** - Phantom browser extension (no `appId` required)
|
|
403
|
+
- **`"google"`** - Google OAuth (requires `appId`)
|
|
404
|
+
- **`"apple"`** - Apple ID (requires `appId`)
|
|
405
|
+
- **`"phantom"`** - Phantom Login (requires `appId`)
|
|
406
|
+
- **`"x"`** - X/Twitter (requires `appId`)
|
|
407
|
+
- **`"tiktok"`** - TikTok (requires `appId`)
|
|
408
|
+
|
|
409
|
+
### Configuration Examples
|
|
410
|
+
|
|
411
|
+
**Browser Extension Only**
|
|
181
412
|
|
|
182
413
|
```tsx
|
|
183
414
|
<PhantomProvider
|
|
184
415
|
config={{
|
|
185
|
-
|
|
416
|
+
providers: ["injected"], // Only allow browser extension
|
|
186
417
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
187
418
|
}}
|
|
188
419
|
>
|
|
@@ -190,11 +421,23 @@ Uses the Phantom browser extension installed by the user.
|
|
|
190
421
|
</PhantomProvider>
|
|
191
422
|
```
|
|
192
423
|
|
|
193
|
-
|
|
424
|
+
**Multiple Authentication Methods**
|
|
194
425
|
|
|
195
|
-
|
|
426
|
+
```tsx
|
|
427
|
+
<PhantomProvider
|
|
428
|
+
config={{
|
|
429
|
+
providers: ["google", "apple", "phantom", "injected"], // Allow all methods
|
|
430
|
+
appId: "your-app-id", // Required for embedded providers
|
|
431
|
+
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
432
|
+
}}
|
|
433
|
+
>
|
|
434
|
+
<YourApp />
|
|
435
|
+
</PhantomProvider>
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
### Embedded Wallet Type
|
|
196
439
|
|
|
197
|
-
|
|
440
|
+
When using embedded providers (google, apple, phantom, etc.), you can specify the wallet type using `embeddedWalletType`. The default is `"user-wallet"`:
|
|
198
441
|
|
|
199
442
|
- **Uses Phantom authentication** - user logs in with existing account
|
|
200
443
|
- **Potentially funded** - brings existing wallet balance
|
|
@@ -203,16 +446,16 @@ Creates non-custodial wallets embedded in your application.
|
|
|
203
446
|
```tsx
|
|
204
447
|
<PhantomProvider
|
|
205
448
|
config={{
|
|
206
|
-
|
|
449
|
+
providers: ["google", "apple", "phantom"],
|
|
207
450
|
appId: "your-app-id",
|
|
208
451
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
452
|
+
embeddedWalletType: "user-wallet", // default, can be omitted
|
|
209
453
|
}}
|
|
210
454
|
>
|
|
211
455
|
<YourApp />
|
|
212
456
|
</PhantomProvider>
|
|
213
457
|
```
|
|
214
458
|
|
|
215
|
-
|
|
216
459
|
## Available Hooks
|
|
217
460
|
|
|
218
461
|
### Core Connection Hooks
|
|
@@ -225,7 +468,7 @@ Connect to wallet:
|
|
|
225
468
|
import { useConnect } from "@phantom/react-sdk";
|
|
226
469
|
|
|
227
470
|
function ConnectButton() {
|
|
228
|
-
const { connect, isConnecting, error } = useConnect();
|
|
471
|
+
const { connect, isConnecting, isLoading, error } = useConnect();
|
|
229
472
|
|
|
230
473
|
const handleConnect = async () => {
|
|
231
474
|
try {
|
|
@@ -236,6 +479,11 @@ function ConnectButton() {
|
|
|
236
479
|
}
|
|
237
480
|
};
|
|
238
481
|
|
|
482
|
+
// Wait for SDK to finish initializing before showing connect button
|
|
483
|
+
if (isLoading) {
|
|
484
|
+
return <div>Loading...</div>;
|
|
485
|
+
}
|
|
486
|
+
|
|
239
487
|
return (
|
|
240
488
|
<button onClick={handleConnect} disabled={isConnecting}>
|
|
241
489
|
{isConnecting ? "Connecting..." : "Connect Wallet"}
|
|
@@ -338,11 +586,7 @@ function PhantomLoginButton() {
|
|
|
338
586
|
return null; // Don't show button if Phantom Login is not available
|
|
339
587
|
}
|
|
340
588
|
|
|
341
|
-
return (
|
|
342
|
-
<button onClick={() => connect({ provider: "phantom" })}>
|
|
343
|
-
Login with Phantom
|
|
344
|
-
</button>
|
|
345
|
-
);
|
|
589
|
+
return <button onClick={() => connect({ provider: "phantom" })}>Login with Phantom</button>;
|
|
346
590
|
}
|
|
347
591
|
```
|
|
348
592
|
|
|
@@ -357,7 +601,12 @@ import { useSolana } from "@phantom/react-sdk";
|
|
|
357
601
|
import { VersionedTransaction, TransactionMessage, SystemProgram, PublicKey, Connection } from "@solana/web3.js";
|
|
358
602
|
|
|
359
603
|
function SolanaOperations() {
|
|
360
|
-
const { solana } = useSolana();
|
|
604
|
+
const { solana, isAvailable } = useSolana();
|
|
605
|
+
|
|
606
|
+
// Check if Solana is available before using it
|
|
607
|
+
if (!isAvailable) {
|
|
608
|
+
return <div>Solana is not available for the current wallet</div>;
|
|
609
|
+
}
|
|
361
610
|
|
|
362
611
|
const signMessage = async () => {
|
|
363
612
|
const signature = await solana.signMessage("Hello Solana!");
|
|
@@ -412,7 +661,19 @@ function SolanaOperations() {
|
|
|
412
661
|
- `switchNetwork(network)` - Switch between mainnet/devnet
|
|
413
662
|
- `getPublicKey()` - Get current public key
|
|
414
663
|
- `isConnected` - Connection status
|
|
415
|
-
- `isAvailable` - Provider availability
|
|
664
|
+
- `isAvailable` - Provider availability (see note below)
|
|
665
|
+
|
|
666
|
+
**Note on `isAvailable`:**
|
|
667
|
+
|
|
668
|
+
The `isAvailable` property indicates whether the Solana chain is available for the currently connected wallet:
|
|
669
|
+
|
|
670
|
+
- **For embedded wallets** (Google, Apple, Phantom Login, etc.): `isAvailable` will be `true` for all networks configured in your `addressTypes` array, as embedded wallets support all configured networks.
|
|
671
|
+
|
|
672
|
+
- **For Phantom injected wallet**: `isAvailable` will be `true` for all networks configured in your `addressTypes` array, as Phantom supports multiple networks.
|
|
673
|
+
|
|
674
|
+
- **For other injected wallets** (discovered via Wallet Standard or EIP-6963): `isAvailable` depends on which networks the specific wallet supports. For example, if you connect to a wallet that only supports Ethereum, `isAvailable` will be `false` for Solana even if Solana is in your `addressTypes` configuration.
|
|
675
|
+
|
|
676
|
+
Always check `isAvailable` before attempting to use chain-specific methods when working with injected wallets that may not support all networks.
|
|
416
677
|
|
|
417
678
|
#### useEthereum
|
|
418
679
|
|
|
@@ -422,7 +683,12 @@ Hook for Ethereum chain operations:
|
|
|
422
683
|
import { useEthereum } from "@phantom/react-sdk";
|
|
423
684
|
|
|
424
685
|
function EthereumOperations() {
|
|
425
|
-
const { ethereum } = useEthereum();
|
|
686
|
+
const { ethereum, isAvailable } = useEthereum();
|
|
687
|
+
|
|
688
|
+
// Check if Ethereum is available before using it
|
|
689
|
+
if (!isAvailable) {
|
|
690
|
+
return <div>Ethereum is not available for the current wallet</div>;
|
|
691
|
+
}
|
|
426
692
|
|
|
427
693
|
const signPersonalMessage = async () => {
|
|
428
694
|
const accounts = await ethereum.getAccounts();
|
|
@@ -511,22 +777,67 @@ function EthereumOperations() {
|
|
|
511
777
|
- `getChainId()` - Get current chain ID
|
|
512
778
|
- `getAccounts()` - Get connected accounts
|
|
513
779
|
- `isConnected` - Connection status
|
|
514
|
-
- `isAvailable` - Provider availability
|
|
780
|
+
- `isAvailable` - Provider availability (see note below)
|
|
781
|
+
|
|
782
|
+
**Note on `isAvailable`:**
|
|
783
|
+
|
|
784
|
+
The `isAvailable` property indicates whether the Ethereum chain is available for the currently connected wallet:
|
|
785
|
+
|
|
786
|
+
- **For embedded wallets** (Google, Apple, Phantom Login, etc.): `isAvailable` will be `true` for all networks configured in your `addressTypes` array, as embedded wallets support all configured networks.
|
|
787
|
+
|
|
788
|
+
- **For Phantom injected wallet**: `isAvailable` will be `true` for all networks configured in your `addressTypes` array, as Phantom supports multiple networks.
|
|
789
|
+
|
|
790
|
+
- **For other injected wallets** (discovered via Wallet Standard or EIP-6963): `isAvailable` depends on which networks the specific wallet supports. For example, if you connect to a wallet that only supports Solana, `isAvailable` will be `false` for Ethereum even if Ethereum is in your `addressTypes` configuration.
|
|
791
|
+
|
|
792
|
+
Always check `isAvailable` before attempting to use chain-specific methods when working with injected wallets that may not support all networks.
|
|
515
793
|
|
|
516
794
|
**Supported EVM Networks:**
|
|
517
795
|
|
|
518
|
-
| Network
|
|
519
|
-
|
|
520
|
-
| Ethereum Mainnet | `1`
|
|
796
|
+
| Network | Chain ID | Usage |
|
|
797
|
+
| ---------------- | ---------- | -------------------------------- |
|
|
798
|
+
| Ethereum Mainnet | `1` | `ethereum.switchChain(1)` |
|
|
521
799
|
| Ethereum Sepolia | `11155111` | `ethereum.switchChain(11155111)` |
|
|
522
|
-
| Polygon Mainnet
|
|
523
|
-
| Polygon Amoy
|
|
524
|
-
| Base Mainnet
|
|
525
|
-
| Base Sepolia
|
|
526
|
-
| Arbitrum One
|
|
527
|
-
| Arbitrum Sepolia | `421614`
|
|
528
|
-
| Monad Mainnet
|
|
529
|
-
| Monad Testnet
|
|
800
|
+
| Polygon Mainnet | `137` | `ethereum.switchChain(137)` |
|
|
801
|
+
| Polygon Amoy | `80002` | `ethereum.switchChain(80002)` |
|
|
802
|
+
| Base Mainnet | `8453` | `ethereum.switchChain(8453)` |
|
|
803
|
+
| Base Sepolia | `84532` | `ethereum.switchChain(84532)` |
|
|
804
|
+
| Arbitrum One | `42161` | `ethereum.switchChain(42161)` |
|
|
805
|
+
| Arbitrum Sepolia | `421614` | `ethereum.switchChain(421614)` |
|
|
806
|
+
| Monad Mainnet | `143` | `ethereum.switchChain(143)` |
|
|
807
|
+
| Monad Testnet | `10143` | `ethereum.switchChain(10143)` |
|
|
808
|
+
|
|
809
|
+
### Wallet Discovery Hook
|
|
810
|
+
|
|
811
|
+
#### useDiscoveredWallets
|
|
812
|
+
|
|
813
|
+
Hook to get discovered injected wallets with automatic loading and error states. Discovers wallets using Wallet Standard (Solana) and EIP-6963 (Ethereum) standards.
|
|
814
|
+
|
|
815
|
+
```tsx
|
|
816
|
+
import { useDiscoveredWallets } from "@phantom/react-sdk";
|
|
817
|
+
|
|
818
|
+
function WalletSelector() {
|
|
819
|
+
const { wallets, isLoading, error, refetch } = useDiscoveredWallets();
|
|
820
|
+
|
|
821
|
+
// wallets: InjectedWalletInfo[] - Array of discovered wallets
|
|
822
|
+
// isLoading: boolean - Loading state during discovery
|
|
823
|
+
// error: Error | null - Error state if discovery fails
|
|
824
|
+
// refetch: () => Promise<void> - Function to manually trigger discovery
|
|
825
|
+
}
|
|
826
|
+
```
|
|
827
|
+
|
|
828
|
+
**Returns:**
|
|
829
|
+
|
|
830
|
+
- `wallets: InjectedWalletInfo[]` - Array of discovered wallet information
|
|
831
|
+
- `isLoading: boolean` - `true` while discovery is in progress
|
|
832
|
+
- `error: Error | null` - Error object if discovery fails, `null` otherwise
|
|
833
|
+
- `refetch: () => Promise<void>` - Async function to manually refresh the wallet list
|
|
834
|
+
|
|
835
|
+
**Behavior:**
|
|
836
|
+
|
|
837
|
+
- Automatically fetches discovered wallets when the SDK becomes available
|
|
838
|
+
- If no wallets are found in the registry, triggers async `discoverWallets()` to discover them
|
|
839
|
+
- Wallets are filtered based on the `addressTypes` configured in `PhantomProvider`
|
|
840
|
+
- Phantom wallet is automatically included if available
|
|
530
841
|
|
|
531
842
|
### Auto-Confirm Hook (Injected Provider Only)
|
|
532
843
|
|
|
@@ -789,37 +1100,45 @@ function EthereumExample() {
|
|
|
789
1100
|
|
|
790
1101
|
Quick reference of all available hooks:
|
|
791
1102
|
|
|
792
|
-
| Hook
|
|
793
|
-
|
|
|
794
|
-
| `useConnect`
|
|
795
|
-
| `
|
|
796
|
-
| `
|
|
797
|
-
| `
|
|
798
|
-
| `
|
|
799
|
-
| `
|
|
800
|
-
| `
|
|
801
|
-
| `
|
|
802
|
-
| `
|
|
1103
|
+
| Hook | Purpose | Returns |
|
|
1104
|
+
| ---------------------------- | --------------------------------------- | --------------------------------------------------- |
|
|
1105
|
+
| `useConnect` | Connect to wallet | `{ connect, isConnecting, error }` |
|
|
1106
|
+
| `useModal` | Control connection modal | `{ open, close, isOpened }` |
|
|
1107
|
+
| `useAccounts` | Get wallet addresses | `WalletAddress[]` or `null` |
|
|
1108
|
+
| `useIsExtensionInstalled` | Check extension status | `{ isLoading, isInstalled }` |
|
|
1109
|
+
| `useIsPhantomLoginAvailable` | Check Phantom Login availability | `{ isLoading, isAvailable }` |
|
|
1110
|
+
| `useDisconnect` | Disconnect from wallet | `{ disconnect, isDisconnecting }` |
|
|
1111
|
+
| `useAutoConfirm` | Auto-confirm management (injected only) | `{ enable, disable, status, supportedChains, ... }` |
|
|
1112
|
+
| `useDiscoveredWallets` | Get discovered injected wallets | `{ wallets, isLoading, error, refetch }` |
|
|
1113
|
+
| `useSolana` | Solana chain operations | `{ signMessage, signAndSendTransaction, ... }` |
|
|
1114
|
+
| `useEthereum` | Ethereum chain operations | `{ signPersonalMessage, sendTransaction, ... }` |
|
|
1115
|
+
| `useTheme` | Access current theme | `PhantomTheme` |
|
|
1116
|
+
| `usePhantom` | Get provider context | `{ isConnected, isReady }` |
|
|
803
1117
|
|
|
804
1118
|
## Configuration Reference
|
|
805
1119
|
|
|
806
1120
|
```typescript
|
|
807
1121
|
interface PhantomSDKConfig {
|
|
808
|
-
|
|
1122
|
+
// List of allowed authentication providers (REQUIRED)
|
|
1123
|
+
providers: AuthProviderType[]; // e.g., ["google", "apple", "phantom", "injected"]
|
|
1124
|
+
|
|
809
1125
|
addressTypes?: [AddressType, ...AddressType[]]; // Networks to enable (e.g., [AddressType.solana])
|
|
810
1126
|
|
|
811
|
-
// Required
|
|
812
|
-
appId
|
|
813
|
-
|
|
1127
|
+
// Required when using embedded providers (google, apple, phantom, x, tiktok)
|
|
1128
|
+
appId?: string; // Your app ID from phantom.com/portal
|
|
1129
|
+
|
|
814
1130
|
// Optional configuration
|
|
815
1131
|
apiBaseUrl?: string; // Phantom API base URL (optional, has default)
|
|
816
1132
|
authOptions?: {
|
|
817
1133
|
authUrl?: string; // Custom auth URL (optional, defaults to "https://connect.phantom.app/login")
|
|
818
1134
|
redirectUrl?: string; // Custom redirect URL after authentication (optional)
|
|
819
1135
|
};
|
|
820
|
-
embeddedWalletType?: "user-wallet"; // Wallet type (optional, defaults to "user-wallet"
|
|
821
|
-
autoConnect?: boolean; // Auto-connect to existing session
|
|
1136
|
+
embeddedWalletType?: "user-wallet"; // Wallet type (optional, defaults to "user-wallet")
|
|
1137
|
+
autoConnect?: boolean; // Auto-connect to existing session (default: true when embedded providers used)
|
|
822
1138
|
}
|
|
1139
|
+
|
|
1140
|
+
// Valid provider types
|
|
1141
|
+
type AuthProviderType = "google" | "apple" | "phantom" | "x" | "tiktok" | "injected";
|
|
823
1142
|
```
|
|
824
1143
|
|
|
825
1144
|
## Debug Configuration
|
|
@@ -849,8 +1168,9 @@ function App() {
|
|
|
849
1168
|
|
|
850
1169
|
// SDK configuration - static, won't change when debug settings change
|
|
851
1170
|
const config: PhantomSDKConfig = {
|
|
852
|
-
|
|
1171
|
+
providers: ["google", "apple", "phantom"],
|
|
853
1172
|
appId: "your-app-id",
|
|
1173
|
+
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
854
1174
|
// ... other config
|
|
855
1175
|
};
|
|
856
1176
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,44 +1,50 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
import * as _phantom_browser_sdk from '@phantom/browser-sdk';
|
|
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';
|
|
6
|
+
import { PhantomTheme } from '@phantom/wallet-sdk-ui';
|
|
7
|
+
export { ComputedPhantomTheme, HexColor, PhantomTheme, darkTheme, lightTheme, mergeTheme, useTheme } from '@phantom/wallet-sdk-ui';
|
|
6
8
|
import { ISolanaChain, IEthereumChain } from '@phantom/chain-interfaces';
|
|
7
9
|
export { EthTransactionRequest, IEthereumChain, ISolanaChain } from '@phantom/chain-interfaces';
|
|
10
|
+
import * as _phantom_embedded_provider_core from '@phantom/embedded-provider-core';
|
|
8
11
|
|
|
9
12
|
type PhantomSDKConfig = BrowserSDKConfig;
|
|
10
13
|
interface PhantomDebugConfig extends DebugConfig {
|
|
11
14
|
}
|
|
12
15
|
interface ConnectOptions {
|
|
13
|
-
providerType?: "injected" | "embedded";
|
|
14
16
|
embeddedWalletType?: "app-wallet" | "user-wallet";
|
|
15
17
|
authOptions?: AuthOptions;
|
|
16
18
|
}
|
|
19
|
+
interface PhantomProviderProps {
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
config: PhantomSDKConfig;
|
|
22
|
+
debugConfig?: PhantomDebugConfig;
|
|
23
|
+
theme?: Partial<PhantomTheme>;
|
|
24
|
+
appIcon?: string;
|
|
25
|
+
appName?: string;
|
|
26
|
+
}
|
|
27
|
+
declare function PhantomProvider({ children, config, debugConfig, theme, appIcon, appName }: PhantomProviderProps): react_jsx_runtime.JSX.Element;
|
|
28
|
+
|
|
17
29
|
interface PhantomContextValue {
|
|
18
30
|
sdk: BrowserSDK | null;
|
|
19
31
|
isConnected: boolean;
|
|
20
32
|
isConnecting: boolean;
|
|
33
|
+
isLoading: boolean;
|
|
21
34
|
connectError: Error | null;
|
|
22
35
|
addresses: WalletAddress[];
|
|
23
|
-
currentProviderType: "injected" | "embedded" | null;
|
|
24
|
-
isPhantomAvailable: boolean;
|
|
25
36
|
isClient: boolean;
|
|
26
37
|
user: ConnectResult | null;
|
|
38
|
+
theme: PhantomTheme;
|
|
39
|
+
allowedProviders: AuthProviderType[];
|
|
27
40
|
}
|
|
28
|
-
interface PhantomProviderProps {
|
|
29
|
-
children: ReactNode;
|
|
30
|
-
config: PhantomSDKConfig;
|
|
31
|
-
debugConfig?: PhantomDebugConfig;
|
|
32
|
-
}
|
|
33
|
-
declare function PhantomProvider({ children, config, debugConfig }: PhantomProviderProps): react_jsx_runtime.JSX.Element;
|
|
34
41
|
declare function usePhantom(): PhantomContextValue;
|
|
35
42
|
|
|
36
43
|
declare function useConnect(): {
|
|
37
|
-
connect: (options: AuthOptions) => Promise<
|
|
44
|
+
connect: (options: AuthOptions) => Promise<_phantom_browser_sdk.ConnectResult>;
|
|
38
45
|
isConnecting: boolean;
|
|
46
|
+
isLoading: boolean;
|
|
39
47
|
error: Error | null;
|
|
40
|
-
currentProviderType: "injected" | "embedded" | null;
|
|
41
|
-
isPhantomAvailable: boolean;
|
|
42
48
|
};
|
|
43
49
|
|
|
44
50
|
declare function useDisconnect(): {
|
|
@@ -47,6 +53,12 @@ declare function useDisconnect(): {
|
|
|
47
53
|
error: Error | null;
|
|
48
54
|
};
|
|
49
55
|
|
|
56
|
+
declare function useModal(): {
|
|
57
|
+
open: () => void;
|
|
58
|
+
close: () => void;
|
|
59
|
+
isOpened: boolean;
|
|
60
|
+
};
|
|
61
|
+
|
|
50
62
|
declare function useAccounts(): _phantom_embedded_provider_core.WalletAddress[] | null;
|
|
51
63
|
|
|
52
64
|
/**
|
|
@@ -98,6 +110,24 @@ declare function useEthereum(): {
|
|
|
98
110
|
isAvailable: boolean;
|
|
99
111
|
};
|
|
100
112
|
|
|
101
|
-
|
|
113
|
+
interface UseDiscoveredWalletsResult {
|
|
114
|
+
wallets: InjectedWalletInfo[];
|
|
115
|
+
isLoading: boolean;
|
|
116
|
+
error: Error | null;
|
|
117
|
+
refetch: () => Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
declare function useDiscoveredWallets(): UseDiscoveredWalletsResult;
|
|
120
|
+
|
|
121
|
+
interface UseModalResult {
|
|
122
|
+
open: () => void;
|
|
123
|
+
close: () => void;
|
|
124
|
+
isOpened: boolean;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
interface ConnectButtonProps {
|
|
128
|
+
addressType?: AddressType;
|
|
129
|
+
fullWidth?: boolean;
|
|
130
|
+
}
|
|
131
|
+
declare function ConnectButton({ addressType, fullWidth }: ConnectButtonProps): react_jsx_runtime.JSX.Element;
|
|
102
132
|
|
|
103
|
-
export { ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomProviderProps, PhantomSDKConfig,
|
|
133
|
+
export { ConnectButton, ConnectButtonProps, ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomProviderProps, PhantomSDKConfig, UseDiscoveredWalletsResult, UseModalResult, useAccounts, useAutoConfirm, useConnect, useDisconnect, useDiscoveredWallets, useEthereum, useIsExtensionInstalled, useIsPhantomLoginAvailable, useModal, usePhantom, useSolana };
|