@phantom/browser-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 +188 -91
- package/dist/index.d.ts +49 -61
- package/dist/index.js +2263 -494
- package/dist/index.mjs +2255 -496
- package/package.json +15 -10
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ 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
|
|
|
@@ -35,14 +35,14 @@ 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
|
});
|
|
@@ -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 (provider parameter
|
|
82
|
-
const { addresses } = await sdk.connect({ provider: "
|
|
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
|
|
@@ -182,39 +183,50 @@ const accounts = await sdk.ethereum.getAccounts();
|
|
|
182
183
|
const isConnected = sdk.ethereum.isConnected();
|
|
183
184
|
```
|
|
184
185
|
|
|
185
|
-
##
|
|
186
|
+
## Authentication Providers
|
|
187
|
+
|
|
188
|
+
The SDK supports multiple authentication providers that you configure via the `providers` array:
|
|
189
|
+
|
|
190
|
+
### Available Providers
|
|
186
191
|
|
|
187
|
-
|
|
192
|
+
- **`"injected"`** - Phantom browser extension (no `appId` required)
|
|
193
|
+
- **`"google"`** - Google OAuth (requires `appId`)
|
|
194
|
+
- **`"apple"`** - Apple ID (requires `appId`)
|
|
195
|
+
- **`"phantom"`** - Phantom Login (requires `appId`)
|
|
196
|
+
- **`"x"`** - X/Twitter (requires `appId`)
|
|
197
|
+
- **`"tiktok"`** - TikTok (requires `appId`)
|
|
188
198
|
|
|
189
|
-
|
|
199
|
+
### Configuration Examples
|
|
200
|
+
|
|
201
|
+
**Injected Provider Only (Browser Extension)**
|
|
190
202
|
|
|
191
203
|
```typescript
|
|
192
204
|
const sdk = new BrowserSDK({
|
|
193
|
-
|
|
205
|
+
providers: ["injected"], // Only allow browser extension
|
|
194
206
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
195
207
|
});
|
|
196
208
|
```
|
|
197
209
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
Creates a non-custodial wallet embedded in your application. Requires API configuration.
|
|
210
|
+
**Multiple Authentication Methods**
|
|
201
211
|
|
|
202
212
|
```typescript
|
|
203
213
|
const sdk = new BrowserSDK({
|
|
204
|
-
|
|
214
|
+
providers: ["google", "apple", "phantom", "injected"], // Allow all methods
|
|
205
215
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
206
|
-
appId: "your-app-id", //
|
|
216
|
+
appId: "your-app-id", // Required for embedded providers (google, apple, phantom, x, tiktok)
|
|
207
217
|
authOptions: {
|
|
208
|
-
authUrl: "https://connect.phantom.app/login", // optional
|
|
218
|
+
authUrl: "https://connect.phantom.app/login", // optional
|
|
209
219
|
redirectUrl: "https://yourapp.com/callback", // optional, defaults to current page
|
|
210
220
|
},
|
|
211
|
-
autoConnect: true, // optional, auto-connect to existing session (default: true
|
|
221
|
+
autoConnect: true, // optional, auto-connect to existing session (default: true when embedded providers are used)
|
|
212
222
|
});
|
|
213
223
|
```
|
|
214
224
|
|
|
215
225
|
### Embedded Wallet Type
|
|
216
226
|
|
|
217
|
-
|
|
227
|
+
When using embedded providers (google, apple, phantom, etc.), you can specify the wallet type:
|
|
228
|
+
|
|
229
|
+
#### User Wallet (`'user-wallet'`) - Default
|
|
218
230
|
|
|
219
231
|
- **Uses Phantom authentication** - user logs in with existing Phantom account
|
|
220
232
|
- **Potentially funded** - brings in user's existing wallet balance
|
|
@@ -223,9 +235,10 @@ const sdk = new BrowserSDK({
|
|
|
223
235
|
|
|
224
236
|
```typescript
|
|
225
237
|
const sdk = new BrowserSDK({
|
|
226
|
-
|
|
238
|
+
providers: ["google", "apple", "phantom"],
|
|
227
239
|
appId: "your-app-id",
|
|
228
240
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
241
|
+
embeddedWalletType: "user-wallet", // default, can be omitted
|
|
229
242
|
});
|
|
230
243
|
```
|
|
231
244
|
|
|
@@ -236,17 +249,16 @@ const sdk = new BrowserSDK({
|
|
|
236
249
|
| `AddressType.solana` | Solana Mainnet, Devnet, Testnet |
|
|
237
250
|
| `AddressType.ethereum` | Ethereum, Polygon, Arbitrum, and more |
|
|
238
251
|
|
|
239
|
-
|
|
240
252
|
### Auto-Connect Feature
|
|
241
253
|
|
|
242
254
|
The SDK can automatically reconnect to existing sessions when instantiated, providing a seamless user experience.
|
|
243
255
|
|
|
244
256
|
```typescript
|
|
245
257
|
const sdk = new BrowserSDK({
|
|
246
|
-
|
|
258
|
+
providers: ["google", "apple", "phantom"],
|
|
247
259
|
appId: "your-app-id",
|
|
248
260
|
addressTypes: [AddressType.solana],
|
|
249
|
-
autoConnect: true, // Default: true
|
|
261
|
+
autoConnect: true, // Default: true when embedded providers are used, false for injected-only
|
|
250
262
|
});
|
|
251
263
|
|
|
252
264
|
// SDK will automatically check for existing valid session and connect in background
|
|
@@ -258,7 +270,7 @@ if (sdk.isConnected()) {
|
|
|
258
270
|
const addresses = await sdk.getAddresses();
|
|
259
271
|
} else {
|
|
260
272
|
// First time or session expired, need to connect manually
|
|
261
|
-
await sdk.connect();
|
|
273
|
+
await sdk.connect({ provider: "google" });
|
|
262
274
|
}
|
|
263
275
|
```
|
|
264
276
|
|
|
@@ -266,14 +278,14 @@ if (sdk.isConnected()) {
|
|
|
266
278
|
|
|
267
279
|
```typescript
|
|
268
280
|
const sdk = new BrowserSDK({
|
|
269
|
-
|
|
281
|
+
providers: ["google", "apple", "phantom"],
|
|
270
282
|
appId: "your-app-id",
|
|
271
283
|
addressTypes: [AddressType.solana],
|
|
272
284
|
autoConnect: false, // Disable auto-connect
|
|
273
285
|
});
|
|
274
286
|
|
|
275
287
|
// Now you must manually call connect() every time
|
|
276
|
-
await sdk.connect();
|
|
288
|
+
await sdk.connect({ provider: "google" });
|
|
277
289
|
```
|
|
278
290
|
|
|
279
291
|
## API Reference
|
|
@@ -288,21 +300,26 @@ new BrowserSDK(config: BrowserSDKConfig)
|
|
|
288
300
|
|
|
289
301
|
```typescript
|
|
290
302
|
interface BrowserSDKConfig {
|
|
291
|
-
|
|
303
|
+
// List of allowed authentication providers (REQUIRED)
|
|
304
|
+
providers: AuthProviderType[]; // e.g., ["google", "apple", "phantom", "injected"]
|
|
305
|
+
|
|
292
306
|
addressTypes?: [AddressType, ...AddressType[]]; // Networks to enable (e.g., [AddressType.solana])
|
|
293
307
|
|
|
294
|
-
// Required
|
|
295
|
-
appId?: string; // Your app ID from phantom.com/portal
|
|
296
|
-
|
|
308
|
+
// Required when using embedded providers (google, apple, phantom, x, tiktok)
|
|
309
|
+
appId?: string; // Your app ID from phantom.com/portal
|
|
310
|
+
|
|
297
311
|
// Optional configuration
|
|
298
312
|
apiBaseUrl?: string; // Phantom API base URL (optional, has default)
|
|
299
313
|
authOptions?: {
|
|
300
314
|
authUrl?: string; // Custom auth URL (optional, defaults to "https://connect.phantom.app/login")
|
|
301
315
|
redirectUrl?: string; // Custom redirect URL after authentication (optional)
|
|
302
316
|
};
|
|
303
|
-
embeddedWalletType?: "user-wallet"; // Wallet type (optional, defaults to "user-wallet"
|
|
304
|
-
autoConnect?: boolean; //
|
|
317
|
+
embeddedWalletType?: "user-wallet"; // Wallet type (optional, defaults to "user-wallet")
|
|
318
|
+
autoConnect?: boolean; // Auto-connect to existing session (default: true when embedded providers used)
|
|
305
319
|
}
|
|
320
|
+
|
|
321
|
+
// Valid provider types
|
|
322
|
+
type AuthProviderType = "google" | "apple" | "phantom" | "x" | "tiktok" | "injected";
|
|
306
323
|
```
|
|
307
324
|
|
|
308
325
|
### Extension Detection
|
|
@@ -347,6 +364,7 @@ if (isAvailable) {
|
|
|
347
364
|
Connect to wallet and get addresses for configured AddressTypes.
|
|
348
365
|
|
|
349
366
|
**Parameters:**
|
|
367
|
+
|
|
350
368
|
- `options: AuthOptions` (required) - Authentication options
|
|
351
369
|
- `provider: "google" | "apple" | "jwt" | "phantom" | "injected"` (required) - Authentication provider to use
|
|
352
370
|
- `jwtToken?: string` (optional) - JWT token (required when `provider` is "jwt")
|
|
@@ -362,7 +380,7 @@ const result = await sdk.connect({ provider: "phantom" });
|
|
|
362
380
|
// Connect with Google authentication
|
|
363
381
|
const result = await sdk.connect({ provider: "google" });
|
|
364
382
|
|
|
365
|
-
// Returns: { addresses: WalletAddress[], status: "pending" | "completed",
|
|
383
|
+
// Returns: { addresses: WalletAddress[], status: "pending" | "completed", provider: "google" | "apple" | "injected" ... }
|
|
366
384
|
// addresses only includes types from addressTypes config
|
|
367
385
|
```
|
|
368
386
|
|
|
@@ -554,18 +572,18 @@ await sdk.ethereum.switchChain(42161); // Arbitrum One
|
|
|
554
572
|
|
|
555
573
|
**Supported EVM Networks:**
|
|
556
574
|
|
|
557
|
-
| Network
|
|
558
|
-
|
|
559
|
-
| Ethereum Mainnet | `1`
|
|
575
|
+
| Network | Chain ID | Usage |
|
|
576
|
+
| ---------------- | ---------- | ----------------------- |
|
|
577
|
+
| Ethereum Mainnet | `1` | `switchChain(1)` |
|
|
560
578
|
| Ethereum Sepolia | `11155111` | `switchChain(11155111)` |
|
|
561
|
-
| Polygon Mainnet
|
|
562
|
-
| Polygon Amoy
|
|
563
|
-
| Base Mainnet
|
|
564
|
-
| Base Sepolia
|
|
565
|
-
| Arbitrum One
|
|
566
|
-
| Arbitrum Sepolia | `421614`
|
|
567
|
-
| Monad Mainnet
|
|
568
|
-
| Monad Testnet
|
|
579
|
+
| Polygon Mainnet | `137` | `switchChain(137)` |
|
|
580
|
+
| Polygon Amoy | `80002` | `switchChain(80002)` |
|
|
581
|
+
| Base Mainnet | `8453` | `switchChain(8453)` |
|
|
582
|
+
| Base Sepolia | `84532` | `switchChain(84532)` |
|
|
583
|
+
| Arbitrum One | `42161` | `switchChain(42161)` |
|
|
584
|
+
| Arbitrum Sepolia | `421614` | `switchChain(421614)` |
|
|
585
|
+
| Monad Mainnet | `143` | `switchChain(143)` |
|
|
586
|
+
| Monad Testnet | `10143` | `switchChain(10143)` |
|
|
569
587
|
|
|
570
588
|
#### getChainId()
|
|
571
589
|
|
|
@@ -602,6 +620,84 @@ Attempt auto-connection using existing session. Should be called after setting u
|
|
|
602
620
|
await sdk.autoConnect();
|
|
603
621
|
```
|
|
604
622
|
|
|
623
|
+
### Wallet Discovery Methods
|
|
624
|
+
|
|
625
|
+
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.
|
|
626
|
+
|
|
627
|
+
#### discoverWallets()
|
|
628
|
+
|
|
629
|
+
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.
|
|
630
|
+
|
|
631
|
+
**Returns:** `Promise<InjectedWalletInfo[]>` - Array of discovered wallet information
|
|
632
|
+
|
|
633
|
+
```typescript
|
|
634
|
+
// Discover wallets asynchronously
|
|
635
|
+
const wallets = await sdk.discoverWallets();
|
|
636
|
+
|
|
637
|
+
console.log("Discovered wallets:", wallets);
|
|
638
|
+
// Example output:
|
|
639
|
+
// [
|
|
640
|
+
// {
|
|
641
|
+
// id: "backpack",
|
|
642
|
+
// name: "Backpack",
|
|
643
|
+
// icon: "https://backpack.app/icon.png",
|
|
644
|
+
// addressTypes: [AddressType.solana],
|
|
645
|
+
// chains: ["solana:mainnet", "solana:devnet"]
|
|
646
|
+
// },
|
|
647
|
+
// {
|
|
648
|
+
// id: "metamask-io",
|
|
649
|
+
// name: "MetaMask",
|
|
650
|
+
// icon: "https://metamask.io/icon.png",
|
|
651
|
+
// addressTypes: [AddressType.ethereum],
|
|
652
|
+
// chains: ["eip155:1", "eip155:5", "eip155:11155111"]
|
|
653
|
+
// }
|
|
654
|
+
// ]
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
**Behavior:**
|
|
658
|
+
|
|
659
|
+
- Automatically filters wallets based on `config.addressTypes`
|
|
660
|
+
- If `addressTypes` is undefined or empty, discovers all wallets regardless of chain support
|
|
661
|
+
- Registers discovered wallets in the internal registry for later retrieval
|
|
662
|
+
- Discovery typically takes ~400ms (EIP-6963 timeout)
|
|
663
|
+
- Returns empty array on error (errors are logged but not thrown)
|
|
664
|
+
|
|
665
|
+
**Note:** Discovery happens automatically when the SDK is instantiated. This method is useful for manually triggering discovery or refreshing the wallet list.
|
|
666
|
+
|
|
667
|
+
#### getDiscoveredWallets()
|
|
668
|
+
|
|
669
|
+
Get all currently discovered wallets from the internal registry. This is a synchronous method that returns wallets that have already been discovered.
|
|
670
|
+
|
|
671
|
+
**Returns:** `InjectedWalletInfo[]` - Array of discovered wallet information
|
|
672
|
+
|
|
673
|
+
```typescript
|
|
674
|
+
// Get already discovered wallets (synchronous)
|
|
675
|
+
const wallets = sdk.getDiscoveredWallets();
|
|
676
|
+
|
|
677
|
+
console.log("Available wallets:", wallets);
|
|
678
|
+
// Returns wallets that match the configured addressTypes
|
|
679
|
+
// Also includes Phantom if available and matches addressTypes
|
|
680
|
+
```
|
|
681
|
+
|
|
682
|
+
**Behavior:**
|
|
683
|
+
|
|
684
|
+
- Returns wallets from the internal registry that match `config.addressTypes`
|
|
685
|
+
- Includes Phantom wallet if `window.phantom` is available and matches configured address types
|
|
686
|
+
- Returns empty array if no wallets are discovered or if an error occurs
|
|
687
|
+
- This is a synchronous read operation - it does not trigger new discovery
|
|
688
|
+
|
|
689
|
+
**Wallet Information Structure:**
|
|
690
|
+
|
|
691
|
+
```typescript
|
|
692
|
+
interface InjectedWalletInfo {
|
|
693
|
+
id: string; // Unique wallet identifier (e.g., "backpack", "metamask-io")
|
|
694
|
+
name: string; // Human-readable wallet name (e.g., "Backpack", "MetaMask")
|
|
695
|
+
icon?: string; // Wallet icon URL (optional)
|
|
696
|
+
addressTypes: AddressType[]; // Supported address types (e.g., [AddressType.solana])
|
|
697
|
+
chains?: string[]; // Supported chains in CAIP-2 format (e.g., ["solana:mainnet"])
|
|
698
|
+
}
|
|
699
|
+
```
|
|
700
|
+
|
|
605
701
|
### Event Handlers
|
|
606
702
|
|
|
607
703
|
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.
|
|
@@ -609,66 +705,66 @@ The SDK provides typed event handlers that allow you to listen for connection st
|
|
|
609
705
|
#### Available Events
|
|
610
706
|
|
|
611
707
|
```typescript
|
|
612
|
-
import { BrowserSDK } from
|
|
708
|
+
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
613
709
|
import type {
|
|
614
710
|
ConnectEventData,
|
|
615
711
|
ConnectStartEventData,
|
|
616
712
|
ConnectErrorEventData,
|
|
617
|
-
DisconnectEventData
|
|
618
|
-
} from
|
|
713
|
+
DisconnectEventData,
|
|
714
|
+
} from "@phantom/browser-sdk";
|
|
619
715
|
|
|
620
716
|
const sdk = new BrowserSDK({
|
|
621
|
-
|
|
622
|
-
appId:
|
|
717
|
+
providers: ["google", "apple", "phantom"],
|
|
718
|
+
appId: "your-app-id",
|
|
623
719
|
addressTypes: [AddressType.solana],
|
|
624
720
|
});
|
|
625
721
|
|
|
626
722
|
// 1. connect_start - Fired when connection starts
|
|
627
|
-
sdk.on(
|
|
628
|
-
console.log(
|
|
629
|
-
console.log(
|
|
723
|
+
sdk.on("connect_start", (data: ConnectStartEventData) => {
|
|
724
|
+
console.log("Connection starting:", data.source); // "auto-connect" | "manual-connect"
|
|
725
|
+
console.log("Auth options:", data.authOptions?.provider); // "google" | "apple" | etc.
|
|
630
726
|
});
|
|
631
727
|
|
|
632
728
|
// 2. connect - Fired when connection succeeds (includes full ConnectResult)
|
|
633
|
-
sdk.on(
|
|
634
|
-
console.log(
|
|
635
|
-
console.log(
|
|
636
|
-
console.log(
|
|
637
|
-
console.log(
|
|
638
|
-
console.log(
|
|
639
|
-
console.log(
|
|
729
|
+
sdk.on("connect", (data: ConnectEventData) => {
|
|
730
|
+
console.log("Connected successfully!");
|
|
731
|
+
console.log("Provider type:", data.provider); // "google" | "apple" | "injected" ...
|
|
732
|
+
console.log("Wallet ID:", data.walletId); // only for embedded providers
|
|
733
|
+
console.log("Addresses:", data.addresses); // WalletAddress[]
|
|
734
|
+
console.log("Status:", data.status); // "pending" | "completed"
|
|
735
|
+
console.log("Source:", data.source); // "auto-connect" | "manual-connect" | "manual-existing" | "existing-session" | "manual"
|
|
640
736
|
});
|
|
641
737
|
|
|
642
738
|
// 3. connect_error - Fired when connection fails
|
|
643
|
-
sdk.on(
|
|
644
|
-
console.error(
|
|
645
|
-
console.log(
|
|
739
|
+
sdk.on("connect_error", (data: ConnectErrorEventData) => {
|
|
740
|
+
console.error("Connection failed:", data.error);
|
|
741
|
+
console.log("Source:", data.source); // "auto-connect" | "manual-connect"
|
|
646
742
|
});
|
|
647
743
|
|
|
648
744
|
// 4. disconnect - Fired when disconnected
|
|
649
|
-
sdk.on(
|
|
650
|
-
console.log(
|
|
651
|
-
console.log(
|
|
745
|
+
sdk.on("disconnect", (data: DisconnectEventData) => {
|
|
746
|
+
console.log("Disconnected from wallet");
|
|
747
|
+
console.log("Source:", data.source); // "manual"
|
|
652
748
|
});
|
|
653
749
|
|
|
654
750
|
// 5. error - General error handler
|
|
655
|
-
sdk.on(
|
|
656
|
-
console.error(
|
|
751
|
+
sdk.on("error", (error: unknown) => {
|
|
752
|
+
console.error("SDK error:", error);
|
|
657
753
|
});
|
|
658
754
|
|
|
659
755
|
// Don't forget to remove listeners when done
|
|
660
|
-
sdk.off(
|
|
756
|
+
sdk.off("connect", handleConnect);
|
|
661
757
|
```
|
|
662
758
|
|
|
663
759
|
#### Event Types
|
|
664
760
|
|
|
665
|
-
| Event
|
|
666
|
-
|
|
667
|
-
| `connect_start` | `ConnectStartEventData` | Connection initiated
|
|
668
|
-
| `connect`
|
|
669
|
-
| `connect_error` | `ConnectErrorEventData` | Connection failed
|
|
670
|
-
| `disconnect`
|
|
671
|
-
| `error`
|
|
761
|
+
| Event | Payload Type | When Fired | Key Data |
|
|
762
|
+
| --------------- | ----------------------- | --------------------- | --------------------------------------------------- |
|
|
763
|
+
| `connect_start` | `ConnectStartEventData` | Connection initiated | `source`, `authOptions` |
|
|
764
|
+
| `connect` | `ConnectEventData` | Connection successful | `provider`, `addresses`, `status`, `source`, `user` |
|
|
765
|
+
| `connect_error` | `ConnectErrorEventData` | Connection failed | `error`, `source` |
|
|
766
|
+
| `disconnect` | `DisconnectEventData` | Disconnected | `source` |
|
|
767
|
+
| `error` | `unknown` | General SDK errors | Error details |
|
|
672
768
|
|
|
673
769
|
#### Using Events with autoConnect()
|
|
674
770
|
|
|
@@ -676,24 +772,24 @@ Event handlers are especially useful with `autoConnect()` since it doesn't retur
|
|
|
676
772
|
|
|
677
773
|
```typescript
|
|
678
774
|
const sdk = new BrowserSDK({
|
|
679
|
-
|
|
680
|
-
appId:
|
|
775
|
+
providers: ["google", "apple", "phantom"],
|
|
776
|
+
appId: "your-app-id",
|
|
681
777
|
addressTypes: [AddressType.solana],
|
|
682
778
|
autoConnect: true,
|
|
683
779
|
});
|
|
684
780
|
|
|
685
781
|
// Set up event listeners BEFORE autoConnect
|
|
686
|
-
sdk.on(
|
|
687
|
-
console.log(
|
|
688
|
-
console.log(
|
|
689
|
-
console.log(
|
|
782
|
+
sdk.on("connect", (data: ConnectEventData) => {
|
|
783
|
+
console.log("Auto-connected successfully!");
|
|
784
|
+
console.log("Provider type:", data.provider);
|
|
785
|
+
console.log("Addresses:", data.addresses);
|
|
690
786
|
|
|
691
787
|
// Update your UI state here
|
|
692
788
|
updateUIWithAddresses(data.addresses);
|
|
693
789
|
});
|
|
694
790
|
|
|
695
|
-
sdk.on(
|
|
696
|
-
console.log(
|
|
791
|
+
sdk.on("connect_error", (data: ConnectErrorEventData) => {
|
|
792
|
+
console.log("Auto-connect failed:", data.error);
|
|
697
793
|
// Show connect button to user
|
|
698
794
|
showConnectButton();
|
|
699
795
|
});
|
|
@@ -838,11 +934,12 @@ interface DebugMessage {
|
|
|
838
934
|
### Example: Debug Console Implementation
|
|
839
935
|
|
|
840
936
|
```typescript
|
|
841
|
-
import { BrowserSDK, DebugLevel } from "@phantom/browser-sdk";
|
|
937
|
+
import { BrowserSDK, DebugLevel, AddressType } from "@phantom/browser-sdk";
|
|
842
938
|
|
|
843
939
|
const sdk = new BrowserSDK({
|
|
844
|
-
|
|
940
|
+
providers: ["google", "apple", "phantom"],
|
|
845
941
|
appId: "your-app-id",
|
|
942
|
+
addressTypes: [AddressType.solana],
|
|
846
943
|
});
|
|
847
944
|
|
|
848
945
|
// Store debug messages
|
|
@@ -907,7 +1004,7 @@ import {
|
|
|
907
1004
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
908
1005
|
|
|
909
1006
|
const sdk = new BrowserSDK({
|
|
910
|
-
|
|
1007
|
+
providers: ["injected"],
|
|
911
1008
|
addressTypes: [AddressType.solana],
|
|
912
1009
|
});
|
|
913
1010
|
|
|
@@ -960,7 +1057,7 @@ import {
|
|
|
960
1057
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
961
1058
|
|
|
962
1059
|
const sdk = new BrowserSDK({
|
|
963
|
-
|
|
1060
|
+
providers: ["injected"],
|
|
964
1061
|
addressTypes: [AddressType.solana],
|
|
965
1062
|
});
|
|
966
1063
|
|
|
@@ -990,7 +1087,7 @@ console.log("Transaction signature:", result.hash);
|
|
|
990
1087
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
991
1088
|
|
|
992
1089
|
const sdk = new BrowserSDK({
|
|
993
|
-
|
|
1090
|
+
providers: ["injected"],
|
|
994
1091
|
addressTypes: [AddressType.ethereum],
|
|
995
1092
|
});
|
|
996
1093
|
|
|
@@ -1024,9 +1121,9 @@ import { parseEther, parseGwei, encodeFunctionData } from "viem";
|
|
|
1024
1121
|
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
|
|
1025
1122
|
|
|
1026
1123
|
const sdk = new BrowserSDK({
|
|
1027
|
-
|
|
1124
|
+
providers: ["google", "apple", "phantom"],
|
|
1125
|
+
appId: "your-app-id",
|
|
1028
1126
|
addressTypes: [AddressType.ethereum],
|
|
1029
|
-
// ... config
|
|
1030
1127
|
});
|
|
1031
1128
|
|
|
1032
1129
|
// Simple transfer with viem utilities
|