@phantom/browser-sdk 1.0.0-beta.9 → 1.0.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 +341 -94
- package/dist/index.d.ts +96 -68
- package/dist/index.js +2755 -678
- package/dist/index.mjs +2750 -683
- package/package.json +15 -10
package/README.md
CHANGED
|
@@ -15,11 +15,11 @@ import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
|
15
15
|
|
|
16
16
|
// Connect to Phantom browser extension
|
|
17
17
|
const sdk = new BrowserSDK({
|
|
18
|
-
|
|
18
|
+
providers: ["injected"], // Only allow browser extension
|
|
19
19
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
-
const { addresses } = await sdk.connect();
|
|
22
|
+
const { addresses } = await sdk.connect({ provider: "injected" });
|
|
23
23
|
console.log("Connected addresses:", addresses);
|
|
24
24
|
|
|
25
25
|
// Chain-specific operations
|
|
@@ -35,19 +35,19 @@ const solanaResult = await sdk.solana.signAndSendTransaction(mySolanaTransaction
|
|
|
35
35
|
const ethResult = await sdk.ethereum.sendTransaction(myEthTransaction);
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
### Embedded Provider
|
|
38
|
+
### Embedded Provider (Multiple Auth Methods)
|
|
39
39
|
|
|
40
40
|
```typescript
|
|
41
41
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
42
42
|
|
|
43
|
-
// Create embedded non-custodial wallet
|
|
43
|
+
// Create embedded non-custodial wallet with multiple auth providers
|
|
44
44
|
const sdk = new BrowserSDK({
|
|
45
|
-
|
|
45
|
+
providers: ["google", "apple", "phantom"], // Allow Google, Apple, and Phantom Login
|
|
46
46
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
47
47
|
appId: "your-app-id", // Get your app ID from phantom.com/portal
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
const { addresses } = await sdk.connect();
|
|
50
|
+
const { addresses } = await sdk.connect({ provider: "phantom" });
|
|
51
51
|
console.log("Addresses:", addresses);
|
|
52
52
|
|
|
53
53
|
// Use chain-specific APIs
|
|
@@ -72,14 +72,15 @@ After instantiating the SDK, use `sdk.connect()` to establish a connection to th
|
|
|
72
72
|
```typescript
|
|
73
73
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
74
74
|
|
|
75
|
-
// 1. Create SDK instance
|
|
75
|
+
// 1. Create SDK instance with allowed providers
|
|
76
76
|
const sdk = new BrowserSDK({
|
|
77
|
-
|
|
77
|
+
providers: ["google", "apple", "phantom", "injected"], // Allowed auth providers
|
|
78
78
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
79
|
+
appId: "your-app-id", // Required when using embedded providers
|
|
79
80
|
});
|
|
80
81
|
|
|
81
|
-
// 2. Connect to wallet
|
|
82
|
-
const { addresses } = await sdk.connect();
|
|
82
|
+
// 2. Connect to wallet (provider parameter must be in allowed providers list)
|
|
83
|
+
const { addresses } = await sdk.connect({ provider: "google" });
|
|
83
84
|
console.log("Connected addresses:", addresses);
|
|
84
85
|
|
|
85
86
|
// 3. Use chain-specific methods
|
|
@@ -93,24 +94,38 @@ const ethResult = await sdk.ethereum.sendTransaction({
|
|
|
93
94
|
|
|
94
95
|
### Connection Options
|
|
95
96
|
|
|
96
|
-
|
|
97
|
+
The `connect()` method requires a `provider` parameter and automatically switches between providers based on the authentication method you specify:
|
|
97
98
|
|
|
98
99
|
```typescript
|
|
99
|
-
//
|
|
100
|
-
|
|
100
|
+
// Connect with injected provider (Phantom extension)
|
|
101
|
+
// Automatically switches to injected provider if not already using it
|
|
102
|
+
const result = await sdk.connect({
|
|
103
|
+
provider: "injected",
|
|
104
|
+
});
|
|
101
105
|
|
|
102
|
-
// Google authentication (
|
|
106
|
+
// Connect with Google authentication (embedded provider)
|
|
107
|
+
// Automatically switches to embedded provider if not already using it
|
|
103
108
|
const result = await sdk.connect({
|
|
104
|
-
|
|
105
|
-
provider: "google",
|
|
106
|
-
},
|
|
109
|
+
provider: "google",
|
|
107
110
|
});
|
|
108
111
|
|
|
109
|
-
// Apple authentication (
|
|
112
|
+
// Connect with Apple authentication (embedded provider)
|
|
113
|
+
// Automatically switches to embedded provider if not already using it
|
|
110
114
|
const result = await sdk.connect({
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
115
|
+
provider: "apple",
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Connect with Phantom authentication (embedded provider)
|
|
119
|
+
// Uses Phantom extension or mobile app for authentication
|
|
120
|
+
// Automatically switches to embedded provider if not already using it
|
|
121
|
+
const result = await sdk.connect({
|
|
122
|
+
provider: "phantom",
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
// Connect with JWT authentication (embedded provider)
|
|
126
|
+
const result = await sdk.connect({
|
|
127
|
+
provider: "jwt",
|
|
128
|
+
jwtToken: "your-jwt-token",
|
|
114
129
|
});
|
|
115
130
|
```
|
|
116
131
|
|
|
@@ -168,39 +183,65 @@ const accounts = await sdk.ethereum.getAccounts();
|
|
|
168
183
|
const isConnected = sdk.ethereum.isConnected();
|
|
169
184
|
```
|
|
170
185
|
|
|
171
|
-
##
|
|
186
|
+
## Authentication Providers
|
|
187
|
+
|
|
188
|
+
The SDK supports multiple authentication providers that you configure via the `providers` array:
|
|
172
189
|
|
|
173
|
-
###
|
|
190
|
+
### Available Providers
|
|
174
191
|
|
|
175
|
-
|
|
192
|
+
- **`"injected"`** - Phantom browser extension
|
|
193
|
+
- **`"google"`** - Google OAuth
|
|
194
|
+
- **`"apple"`** - Apple ID
|
|
195
|
+
- **`"phantom"`** - Phantom Login
|
|
196
|
+
- **`"deeplink"`** - Deeplink to Phantom mobile app (only renders on mobile devices)
|
|
197
|
+
|
|
198
|
+
### Configuration Examples
|
|
199
|
+
|
|
200
|
+
**Injected Provider Only (Browser Extension)**
|
|
176
201
|
|
|
177
202
|
```typescript
|
|
178
203
|
const sdk = new BrowserSDK({
|
|
179
|
-
|
|
204
|
+
providers: ["injected"], // Only allow browser extension
|
|
180
205
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
181
206
|
});
|
|
182
207
|
```
|
|
183
208
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
Creates a non-custodial wallet embedded in your application. Requires API configuration.
|
|
209
|
+
**Multiple Authentication Methods**
|
|
187
210
|
|
|
188
211
|
```typescript
|
|
189
212
|
const sdk = new BrowserSDK({
|
|
190
|
-
|
|
213
|
+
providers: ["google", "apple", "phantom", "injected", "deeplink"], // Allow all methods
|
|
191
214
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
192
|
-
appId: "your-app-id", //
|
|
215
|
+
appId: "your-app-id", // Required for embedded providers (google, apple, phantom, deeplink)
|
|
193
216
|
authOptions: {
|
|
194
|
-
authUrl: "https://connect.phantom.app/login", // optional
|
|
217
|
+
authUrl: "https://connect.phantom.app/login", // optional
|
|
195
218
|
redirectUrl: "https://yourapp.com/callback", // optional, defaults to current page
|
|
196
219
|
},
|
|
197
|
-
autoConnect: true, // optional, auto-connect to existing session (default: true
|
|
220
|
+
autoConnect: true, // optional, auto-connect to existing session (default: true when embedded providers are used)
|
|
221
|
+
});
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**Mobile Deeplink Support**
|
|
225
|
+
|
|
226
|
+
The `"deeplink"` provider enables a button that opens the Phantom mobile app on mobile devices. This button only appears on mobile devices when the Phantom browser extension is not installed. When clicked, it redirects users to the Phantom mobile app to complete authentication.
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
const sdk = new BrowserSDK({
|
|
230
|
+
providers: ["google", "apple", "phantom", "deeplink"], // Include deeplink for mobile support
|
|
231
|
+
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
232
|
+
appId: "your-app-id", // Required for deeplink
|
|
233
|
+
authOptions: {
|
|
234
|
+
authUrl: "https://connect.phantom.app/login",
|
|
235
|
+
redirectUrl: "https://yourapp.com/callback",
|
|
236
|
+
},
|
|
198
237
|
});
|
|
199
238
|
```
|
|
200
239
|
|
|
201
240
|
### Embedded Wallet Type
|
|
202
241
|
|
|
203
|
-
|
|
242
|
+
When using embedded providers (google, apple, phantom, etc.), you can specify the wallet type:
|
|
243
|
+
|
|
244
|
+
#### User Wallet (`'user-wallet'`) - Default
|
|
204
245
|
|
|
205
246
|
- **Uses Phantom authentication** - user logs in with existing Phantom account
|
|
206
247
|
- **Potentially funded** - brings in user's existing wallet balance
|
|
@@ -209,9 +250,10 @@ const sdk = new BrowserSDK({
|
|
|
209
250
|
|
|
210
251
|
```typescript
|
|
211
252
|
const sdk = new BrowserSDK({
|
|
212
|
-
|
|
253
|
+
providers: ["google", "apple", "phantom"],
|
|
213
254
|
appId: "your-app-id",
|
|
214
255
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
256
|
+
embeddedWalletType: "user-wallet", // default, can be omitted
|
|
215
257
|
});
|
|
216
258
|
```
|
|
217
259
|
|
|
@@ -222,17 +264,16 @@ const sdk = new BrowserSDK({
|
|
|
222
264
|
| `AddressType.solana` | Solana Mainnet, Devnet, Testnet |
|
|
223
265
|
| `AddressType.ethereum` | Ethereum, Polygon, Arbitrum, and more |
|
|
224
266
|
|
|
225
|
-
|
|
226
267
|
### Auto-Connect Feature
|
|
227
268
|
|
|
228
269
|
The SDK can automatically reconnect to existing sessions when instantiated, providing a seamless user experience.
|
|
229
270
|
|
|
230
271
|
```typescript
|
|
231
272
|
const sdk = new BrowserSDK({
|
|
232
|
-
|
|
273
|
+
providers: ["google", "apple", "phantom"],
|
|
233
274
|
appId: "your-app-id",
|
|
234
275
|
addressTypes: [AddressType.solana],
|
|
235
|
-
autoConnect: true, // Default: true
|
|
276
|
+
autoConnect: true, // Default: true when embedded providers are used, false for injected-only
|
|
236
277
|
});
|
|
237
278
|
|
|
238
279
|
// SDK will automatically check for existing valid session and connect in background
|
|
@@ -244,7 +285,7 @@ if (sdk.isConnected()) {
|
|
|
244
285
|
const addresses = await sdk.getAddresses();
|
|
245
286
|
} else {
|
|
246
287
|
// First time or session expired, need to connect manually
|
|
247
|
-
await sdk.connect();
|
|
288
|
+
await sdk.connect({ provider: "google" });
|
|
248
289
|
}
|
|
249
290
|
```
|
|
250
291
|
|
|
@@ -252,14 +293,14 @@ if (sdk.isConnected()) {
|
|
|
252
293
|
|
|
253
294
|
```typescript
|
|
254
295
|
const sdk = new BrowserSDK({
|
|
255
|
-
|
|
296
|
+
providers: ["google", "apple", "phantom"],
|
|
256
297
|
appId: "your-app-id",
|
|
257
298
|
addressTypes: [AddressType.solana],
|
|
258
299
|
autoConnect: false, // Disable auto-connect
|
|
259
300
|
});
|
|
260
301
|
|
|
261
302
|
// Now you must manually call connect() every time
|
|
262
|
-
await sdk.connect();
|
|
303
|
+
await sdk.connect({ provider: "google" });
|
|
263
304
|
```
|
|
264
305
|
|
|
265
306
|
## API Reference
|
|
@@ -274,26 +315,33 @@ new BrowserSDK(config: BrowserSDKConfig)
|
|
|
274
315
|
|
|
275
316
|
```typescript
|
|
276
317
|
interface BrowserSDKConfig {
|
|
277
|
-
|
|
318
|
+
// List of allowed authentication providers (REQUIRED)
|
|
319
|
+
providers: AuthProviderType[]; // e.g., ["google", "apple", "phantom", "injected", "deeplink"]
|
|
320
|
+
|
|
278
321
|
addressTypes?: [AddressType, ...AddressType[]]; // Networks to enable (e.g., [AddressType.solana])
|
|
279
322
|
|
|
280
|
-
// Required
|
|
281
|
-
appId?: string; // Your app ID from phantom.com/portal
|
|
282
|
-
|
|
323
|
+
// Required when using embedded providers (google, apple, phantom)
|
|
324
|
+
appId?: string; // Your app ID from phantom.com/portal
|
|
325
|
+
|
|
283
326
|
// Optional configuration
|
|
284
327
|
apiBaseUrl?: string; // Phantom API base URL (optional, has default)
|
|
285
328
|
authOptions?: {
|
|
286
329
|
authUrl?: string; // Custom auth URL (optional, defaults to "https://connect.phantom.app/login")
|
|
287
330
|
redirectUrl?: string; // Custom redirect URL after authentication (optional)
|
|
288
331
|
};
|
|
289
|
-
embeddedWalletType?: "user-wallet"; // Wallet type (optional, defaults to "user-wallet"
|
|
290
|
-
autoConnect?: boolean; //
|
|
332
|
+
embeddedWalletType?: "user-wallet"; // Wallet type (optional, defaults to "user-wallet")
|
|
333
|
+
autoConnect?: boolean; // Auto-connect to existing session (default: true when embedded providers used)
|
|
291
334
|
}
|
|
335
|
+
|
|
336
|
+
// Valid provider types
|
|
337
|
+
type AuthProviderType = "google" | "apple" | "phantom" | "injected" | "deeplink";
|
|
292
338
|
```
|
|
293
339
|
|
|
294
340
|
### Extension Detection
|
|
295
341
|
|
|
296
|
-
|
|
342
|
+
#### waitForPhantomExtension
|
|
343
|
+
|
|
344
|
+
Check if the Phantom extension is installed:
|
|
297
345
|
|
|
298
346
|
```typescript
|
|
299
347
|
import { waitForPhantomExtension } from "@phantom/browser-sdk";
|
|
@@ -307,15 +355,47 @@ if (isAvailable) {
|
|
|
307
355
|
}
|
|
308
356
|
```
|
|
309
357
|
|
|
358
|
+
#### isPhantomLoginAvailable
|
|
359
|
+
|
|
360
|
+
Check if Phantom Login is available (requires extension to be installed and support the `phantom_login` feature):
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
import { isPhantomLoginAvailable } from "@phantom/browser-sdk";
|
|
364
|
+
|
|
365
|
+
const isAvailable = await isPhantomLoginAvailable();
|
|
366
|
+
|
|
367
|
+
if (isAvailable) {
|
|
368
|
+
console.log("Phantom Login is available!");
|
|
369
|
+
// Can use provider: "phantom" in connect()
|
|
370
|
+
} else {
|
|
371
|
+
console.log("Phantom Login is not available");
|
|
372
|
+
}
|
|
373
|
+
```
|
|
374
|
+
|
|
310
375
|
### Core Methods
|
|
311
376
|
|
|
312
|
-
#### connect()
|
|
377
|
+
#### connect(options)
|
|
313
378
|
|
|
314
379
|
Connect to wallet and get addresses for configured AddressTypes.
|
|
315
380
|
|
|
381
|
+
**Parameters:**
|
|
382
|
+
|
|
383
|
+
- `options: AuthOptions` (required) - Authentication options
|
|
384
|
+
- `provider: "google" | "apple" | "jwt" | "phantom" | "injected"` (required) - Authentication provider to use
|
|
385
|
+
- `jwtToken?: string` (optional) - JWT token (required when `provider` is "jwt")
|
|
386
|
+
- `customAuthData?: Record<string, any>` (optional) - Custom authentication data
|
|
387
|
+
|
|
316
388
|
```typescript
|
|
317
|
-
|
|
318
|
-
|
|
389
|
+
// Connect with injected provider
|
|
390
|
+
const result = await sdk.connect({ provider: "injected" });
|
|
391
|
+
|
|
392
|
+
// Connect with Phantom authentication
|
|
393
|
+
const result = await sdk.connect({ provider: "phantom" });
|
|
394
|
+
|
|
395
|
+
// Connect with Google authentication
|
|
396
|
+
const result = await sdk.connect({ provider: "google" });
|
|
397
|
+
|
|
398
|
+
// Returns: { addresses: WalletAddress[], status: "pending" | "completed", provider: "google" | "apple" | "injected" ... }
|
|
319
399
|
// addresses only includes types from addressTypes config
|
|
320
400
|
```
|
|
321
401
|
|
|
@@ -344,15 +424,6 @@ Check if SDK is connected to a wallet.
|
|
|
344
424
|
const connected = sdk.isConnected();
|
|
345
425
|
```
|
|
346
426
|
|
|
347
|
-
#### getWalletId()
|
|
348
|
-
|
|
349
|
-
Get the wallet ID (embedded wallets only).
|
|
350
|
-
|
|
351
|
-
```typescript
|
|
352
|
-
const walletId = sdk.getWalletId();
|
|
353
|
-
// Returns string for embedded wallets, null for injected
|
|
354
|
-
```
|
|
355
|
-
|
|
356
427
|
### Solana Chain Methods
|
|
357
428
|
|
|
358
429
|
#### signMessage(message)
|
|
@@ -506,7 +577,7 @@ const result = await sdk.ethereum.sendTransaction({
|
|
|
506
577
|
|
|
507
578
|
#### switchChain(chainId)
|
|
508
579
|
|
|
509
|
-
Switch to a different Ethereum chain.
|
|
580
|
+
Switch to a different Ethereum chain. Accepts a chain ID as a number or a hex string value.
|
|
510
581
|
|
|
511
582
|
```typescript
|
|
512
583
|
await sdk.ethereum.switchChain(1); // Ethereum mainnet
|
|
@@ -514,6 +585,21 @@ await sdk.ethereum.switchChain(137); // Polygon
|
|
|
514
585
|
await sdk.ethereum.switchChain(42161); // Arbitrum One
|
|
515
586
|
```
|
|
516
587
|
|
|
588
|
+
**Supported EVM Networks:**
|
|
589
|
+
|
|
590
|
+
| Network | Chain ID | Usage |
|
|
591
|
+
| ---------------- | ---------- | ----------------------- |
|
|
592
|
+
| Ethereum Mainnet | `1` | `switchChain(1)` |
|
|
593
|
+
| Ethereum Sepolia | `11155111` | `switchChain(11155111)` |
|
|
594
|
+
| Polygon Mainnet | `137` | `switchChain(137)` |
|
|
595
|
+
| Polygon Amoy | `80002` | `switchChain(80002)` |
|
|
596
|
+
| Base Mainnet | `8453` | `switchChain(8453)` |
|
|
597
|
+
| Base Sepolia | `84532` | `switchChain(84532)` |
|
|
598
|
+
| Arbitrum One | `42161` | `switchChain(42161)` |
|
|
599
|
+
| Arbitrum Sepolia | `421614` | `switchChain(421614)` |
|
|
600
|
+
| Monad Mainnet | `143` | `switchChain(143)` |
|
|
601
|
+
| Monad Testnet | `10143` | `switchChain(10143)` |
|
|
602
|
+
|
|
517
603
|
#### getChainId()
|
|
518
604
|
|
|
519
605
|
Get the current chain ID.
|
|
@@ -549,6 +635,184 @@ Attempt auto-connection using existing session. Should be called after setting u
|
|
|
549
635
|
await sdk.autoConnect();
|
|
550
636
|
```
|
|
551
637
|
|
|
638
|
+
### Wallet Discovery Methods
|
|
639
|
+
|
|
640
|
+
The SDK can discover multiple injected wallets using Wallet Standard for Solana and EIP-6963 for Ethereum. This allows users to choose from any installed wallet that supports the configured address types.
|
|
641
|
+
|
|
642
|
+
#### discoverWallets()
|
|
643
|
+
|
|
644
|
+
Asynchronously discover all available injected wallets that support the configured address types. This method uses Wallet Standard (`navigator.wallets.getWallets()`) for Solana wallets and EIP-6963 events for Ethereum wallets.
|
|
645
|
+
|
|
646
|
+
**Returns:** `Promise<InjectedWalletInfo[]>` - Array of discovered wallet information
|
|
647
|
+
|
|
648
|
+
```typescript
|
|
649
|
+
// Discover wallets asynchronously
|
|
650
|
+
const wallets = await sdk.discoverWallets();
|
|
651
|
+
|
|
652
|
+
console.log("Discovered wallets:", wallets);
|
|
653
|
+
// Example output:
|
|
654
|
+
// [
|
|
655
|
+
// {
|
|
656
|
+
// id: "backpack",
|
|
657
|
+
// name: "Backpack",
|
|
658
|
+
// icon: "https://backpack.app/icon.png",
|
|
659
|
+
// addressTypes: [AddressType.solana],
|
|
660
|
+
// chains: ["solana:mainnet", "solana:devnet"]
|
|
661
|
+
// },
|
|
662
|
+
// {
|
|
663
|
+
// id: "metamask-io",
|
|
664
|
+
// name: "MetaMask",
|
|
665
|
+
// icon: "https://metamask.io/icon.png",
|
|
666
|
+
// addressTypes: [AddressType.ethereum],
|
|
667
|
+
// chains: ["eip155:1", "eip155:5", "eip155:11155111"]
|
|
668
|
+
// }
|
|
669
|
+
// ]
|
|
670
|
+
```
|
|
671
|
+
|
|
672
|
+
**Behavior:**
|
|
673
|
+
|
|
674
|
+
- Automatically filters wallets based on `config.addressTypes`
|
|
675
|
+
- If `addressTypes` is undefined or empty, discovers all wallets regardless of chain support
|
|
676
|
+
- Registers discovered wallets in the internal registry for later retrieval
|
|
677
|
+
- Discovery typically takes ~400ms (EIP-6963 timeout)
|
|
678
|
+
- Returns empty array on error (errors are logged but not thrown)
|
|
679
|
+
|
|
680
|
+
**Note:** Discovery happens automatically when the SDK is instantiated. This method is useful for manually triggering discovery or refreshing the wallet list.
|
|
681
|
+
|
|
682
|
+
#### getDiscoveredWallets()
|
|
683
|
+
|
|
684
|
+
Get all currently discovered wallets from the internal registry. This is a synchronous method that returns wallets that have already been discovered.
|
|
685
|
+
|
|
686
|
+
**Returns:** `InjectedWalletInfo[]` - Array of discovered wallet information
|
|
687
|
+
|
|
688
|
+
```typescript
|
|
689
|
+
// Get already discovered wallets (synchronous)
|
|
690
|
+
const wallets = sdk.getDiscoveredWallets();
|
|
691
|
+
|
|
692
|
+
console.log("Available wallets:", wallets);
|
|
693
|
+
// Returns wallets that match the configured addressTypes
|
|
694
|
+
// Also includes Phantom if available and matches addressTypes
|
|
695
|
+
```
|
|
696
|
+
|
|
697
|
+
**Behavior:**
|
|
698
|
+
|
|
699
|
+
- Returns wallets from the internal registry that match `config.addressTypes`
|
|
700
|
+
- Includes Phantom wallet if `window.phantom` is available and matches configured address types
|
|
701
|
+
- Returns empty array if no wallets are discovered or if an error occurs
|
|
702
|
+
- This is a synchronous read operation - it does not trigger new discovery
|
|
703
|
+
|
|
704
|
+
**Wallet Information Structure:**
|
|
705
|
+
|
|
706
|
+
```typescript
|
|
707
|
+
interface InjectedWalletInfo {
|
|
708
|
+
id: string; // Unique wallet identifier (e.g., "backpack", "metamask-io")
|
|
709
|
+
name: string; // Human-readable wallet name (e.g., "Backpack", "MetaMask")
|
|
710
|
+
icon?: string; // Wallet icon URL (optional)
|
|
711
|
+
addressTypes: AddressType[]; // Supported address types (e.g., [AddressType.solana])
|
|
712
|
+
chains?: string[]; // Supported chains in CAIP-2 format (e.g., ["solana:mainnet"])
|
|
713
|
+
}
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
### Event Handlers
|
|
717
|
+
|
|
718
|
+
The SDK provides typed event handlers that allow you to listen for connection state changes. This is especially useful for `autoConnect()` flows where you need to track the connection result.
|
|
719
|
+
|
|
720
|
+
#### Available Events
|
|
721
|
+
|
|
722
|
+
```typescript
|
|
723
|
+
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
724
|
+
import type {
|
|
725
|
+
ConnectEventData,
|
|
726
|
+
ConnectStartEventData,
|
|
727
|
+
ConnectErrorEventData,
|
|
728
|
+
DisconnectEventData,
|
|
729
|
+
} from "@phantom/browser-sdk";
|
|
730
|
+
|
|
731
|
+
const sdk = new BrowserSDK({
|
|
732
|
+
providers: ["google", "apple", "phantom"],
|
|
733
|
+
appId: "your-app-id",
|
|
734
|
+
addressTypes: [AddressType.solana],
|
|
735
|
+
});
|
|
736
|
+
|
|
737
|
+
// 1. connect_start - Fired when connection starts
|
|
738
|
+
sdk.on("connect_start", (data: ConnectStartEventData) => {
|
|
739
|
+
console.log("Connection starting:", data.source); // "auto-connect" | "manual-connect"
|
|
740
|
+
console.log("Auth options:", data.authOptions?.provider); // "google" | "apple" | etc.
|
|
741
|
+
});
|
|
742
|
+
|
|
743
|
+
// 2. connect - Fired when connection succeeds (includes full ConnectResult)
|
|
744
|
+
sdk.on("connect", (data: ConnectEventData) => {
|
|
745
|
+
console.log("Connected successfully!");
|
|
746
|
+
console.log("Provider type:", data.provider); // "google" | "apple" | "injected" ...
|
|
747
|
+
console.log("Wallet ID:", data.walletId); // only for embedded providers
|
|
748
|
+
console.log("Addresses:", data.addresses); // WalletAddress[]
|
|
749
|
+
console.log("Status:", data.status); // "pending" | "completed"
|
|
750
|
+
console.log("Source:", data.source); // "auto-connect" | "manual-connect" | "manual-existing" | "existing-session" | "manual"
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
// 3. connect_error - Fired when connection fails
|
|
754
|
+
sdk.on("connect_error", (data: ConnectErrorEventData) => {
|
|
755
|
+
console.error("Connection failed:", data.error);
|
|
756
|
+
console.log("Source:", data.source); // "auto-connect" | "manual-connect"
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
// 4. disconnect - Fired when disconnected
|
|
760
|
+
sdk.on("disconnect", (data: DisconnectEventData) => {
|
|
761
|
+
console.log("Disconnected from wallet");
|
|
762
|
+
console.log("Source:", data.source); // "manual"
|
|
763
|
+
});
|
|
764
|
+
|
|
765
|
+
// 5. error - General error handler
|
|
766
|
+
sdk.on("error", (error: unknown) => {
|
|
767
|
+
console.error("SDK error:", error);
|
|
768
|
+
});
|
|
769
|
+
|
|
770
|
+
// Don't forget to remove listeners when done
|
|
771
|
+
sdk.off("connect", handleConnect);
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
#### Event Types
|
|
775
|
+
|
|
776
|
+
| Event | Payload Type | When Fired | Key Data |
|
|
777
|
+
| --------------- | ----------------------- | --------------------- | --------------------------------------------------- |
|
|
778
|
+
| `connect_start` | `ConnectStartEventData` | Connection initiated | `source`, `authOptions` |
|
|
779
|
+
| `connect` | `ConnectEventData` | Connection successful | `provider`, `addresses`, `status`, `source`, `user` |
|
|
780
|
+
| `connect_error` | `ConnectErrorEventData` | Connection failed | `error`, `source` |
|
|
781
|
+
| `disconnect` | `DisconnectEventData` | Disconnected | `source` |
|
|
782
|
+
| `error` | `unknown` | General SDK errors | Error details |
|
|
783
|
+
|
|
784
|
+
#### Using Events with autoConnect()
|
|
785
|
+
|
|
786
|
+
Event handlers are especially useful with `autoConnect()` since it doesn't return a value:
|
|
787
|
+
|
|
788
|
+
```typescript
|
|
789
|
+
const sdk = new BrowserSDK({
|
|
790
|
+
providers: ["google", "apple", "phantom"],
|
|
791
|
+
appId: "your-app-id",
|
|
792
|
+
addressTypes: [AddressType.solana],
|
|
793
|
+
autoConnect: true,
|
|
794
|
+
});
|
|
795
|
+
|
|
796
|
+
// Set up event listeners BEFORE autoConnect
|
|
797
|
+
sdk.on("connect", (data: ConnectEventData) => {
|
|
798
|
+
console.log("Auto-connected successfully!");
|
|
799
|
+
console.log("Provider type:", data.provider);
|
|
800
|
+
console.log("Addresses:", data.addresses);
|
|
801
|
+
|
|
802
|
+
// Update your UI state here
|
|
803
|
+
updateUIWithAddresses(data.addresses);
|
|
804
|
+
});
|
|
805
|
+
|
|
806
|
+
sdk.on("connect_error", (data: ConnectErrorEventData) => {
|
|
807
|
+
console.log("Auto-connect failed:", data.error);
|
|
808
|
+
// Show connect button to user
|
|
809
|
+
showConnectButton();
|
|
810
|
+
});
|
|
811
|
+
|
|
812
|
+
// Auto-connect will trigger events
|
|
813
|
+
await sdk.autoConnect();
|
|
814
|
+
```
|
|
815
|
+
|
|
552
816
|
### Auto-Confirm Methods (Injected Provider Only)
|
|
553
817
|
|
|
554
818
|
The SDK provides auto-confirm functionality that allows automatic transaction confirmation for specified chains. This feature is only available when using the injected provider (Phantom browser extension).
|
|
@@ -606,33 +870,15 @@ console.log("Supported chains:", supportedChains.chains);
|
|
|
606
870
|
|
|
607
871
|
#### Available NetworkId Values
|
|
608
872
|
|
|
873
|
+
For a complete list of supported networks including Solana, Ethereum, Polygon, Base, Arbitrum, Monad, and more, see the [Network Support section in the main README](../../README.md#network-support).
|
|
874
|
+
|
|
609
875
|
```typescript
|
|
610
876
|
import { NetworkId } from "@phantom/browser-sdk";
|
|
611
877
|
|
|
612
|
-
//
|
|
613
|
-
|
|
614
|
-
NetworkId.
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
// Ethereum networks
|
|
618
|
-
NetworkId.ETHEREUM_MAINNET; // "eip155:1"
|
|
619
|
-
NetworkId.ETHEREUM_SEPOLIA; // "eip155:11155111"
|
|
620
|
-
|
|
621
|
-
// Polygon networks
|
|
622
|
-
NetworkId.POLYGON_MAINNET; // "eip155:137"
|
|
623
|
-
NetworkId.POLYGON_AMOY; // "eip155:80002"
|
|
624
|
-
|
|
625
|
-
// Arbitrum networks
|
|
626
|
-
NetworkId.ARBITRUM_ONE; // "eip155:42161"
|
|
627
|
-
NetworkId.ARBITRUM_SEPOLIA; // "eip155:421614"
|
|
628
|
-
|
|
629
|
-
// Optimism networks
|
|
630
|
-
NetworkId.OPTIMISM_MAINNET; // "eip155:10"
|
|
631
|
-
NetworkId.OPTIMISM_GOERLI; // "eip155:420"
|
|
632
|
-
|
|
633
|
-
// Base networks
|
|
634
|
-
NetworkId.BASE_MAINNET; // "eip155:8453"
|
|
635
|
-
NetworkId.BASE_SEPOLIA; // "eip155:84532"
|
|
878
|
+
// Example: Use NetworkId for auto-confirm
|
|
879
|
+
await sdk.enableAutoConfirm({
|
|
880
|
+
chains: [NetworkId.SOLANA_MAINNET, NetworkId.ETHEREUM_MAINNET],
|
|
881
|
+
});
|
|
636
882
|
```
|
|
637
883
|
|
|
638
884
|
**Important Notes:**
|
|
@@ -703,11 +949,12 @@ interface DebugMessage {
|
|
|
703
949
|
### Example: Debug Console Implementation
|
|
704
950
|
|
|
705
951
|
```typescript
|
|
706
|
-
import { BrowserSDK, DebugLevel } from "@phantom/browser-sdk";
|
|
952
|
+
import { BrowserSDK, DebugLevel, AddressType } from "@phantom/browser-sdk";
|
|
707
953
|
|
|
708
954
|
const sdk = new BrowserSDK({
|
|
709
|
-
|
|
955
|
+
providers: ["google", "apple", "phantom"],
|
|
710
956
|
appId: "your-app-id",
|
|
957
|
+
addressTypes: [AddressType.solana],
|
|
711
958
|
});
|
|
712
959
|
|
|
713
960
|
// Store debug messages
|
|
@@ -772,11 +1019,11 @@ import {
|
|
|
772
1019
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
773
1020
|
|
|
774
1021
|
const sdk = new BrowserSDK({
|
|
775
|
-
|
|
1022
|
+
providers: ["injected"],
|
|
776
1023
|
addressTypes: [AddressType.solana],
|
|
777
1024
|
});
|
|
778
1025
|
|
|
779
|
-
await sdk.connect();
|
|
1026
|
+
await sdk.connect({ provider: "injected" });
|
|
780
1027
|
|
|
781
1028
|
// Get recent blockhash
|
|
782
1029
|
const connection = new Connection("https://api.mainnet-beta.solana.com");
|
|
@@ -825,11 +1072,11 @@ import {
|
|
|
825
1072
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
826
1073
|
|
|
827
1074
|
const sdk = new BrowserSDK({
|
|
828
|
-
|
|
1075
|
+
providers: ["injected"],
|
|
829
1076
|
addressTypes: [AddressType.solana],
|
|
830
1077
|
});
|
|
831
1078
|
|
|
832
|
-
await sdk.connect();
|
|
1079
|
+
await sdk.connect({ provider: "injected" });
|
|
833
1080
|
|
|
834
1081
|
// Create transaction with @solana/kit
|
|
835
1082
|
const rpc = createSolanaRpc("https://api.mainnet-beta.solana.com");
|
|
@@ -855,11 +1102,11 @@ console.log("Transaction signature:", result.hash);
|
|
|
855
1102
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
856
1103
|
|
|
857
1104
|
const sdk = new BrowserSDK({
|
|
858
|
-
|
|
1105
|
+
providers: ["injected"],
|
|
859
1106
|
addressTypes: [AddressType.ethereum],
|
|
860
1107
|
});
|
|
861
1108
|
|
|
862
|
-
await sdk.connect();
|
|
1109
|
+
await sdk.connect({ provider: "injected" });
|
|
863
1110
|
|
|
864
1111
|
// Simple ETH transfer
|
|
865
1112
|
const result = await sdk.ethereum.sendTransaction({
|
|
@@ -889,9 +1136,9 @@ import { parseEther, parseGwei, encodeFunctionData } from "viem";
|
|
|
889
1136
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
890
1137
|
|
|
891
1138
|
const sdk = new BrowserSDK({
|
|
892
|
-
|
|
1139
|
+
providers: ["google", "apple", "phantom"],
|
|
1140
|
+
appId: "your-app-id",
|
|
893
1141
|
addressTypes: [AddressType.ethereum],
|
|
894
|
-
// ... config
|
|
895
1142
|
});
|
|
896
1143
|
|
|
897
1144
|
// Simple transfer with viem utilities
|