internet-court/internet-court-skill / vendored/dflow/dflow-phantom-connect
dflow-phantom-connect
VerifiedBuild Solana wallet-connected apps with Phantom Connect SDKs and DFlow spot trading. Use when user asks to connect a Phantom wallet, integrate Phantom in React, React Native, or vanilla JS, sign messages or transactions, build token-gated pages, mint NFTs, accept crypto payments, or swap/stream tokens with DFlow. Covers @phantom/react-sdk, @phantom/react-native-sdk, @phantom/browser-sdk, and DFlow spot trading and market-data streaming. Do NOT use for Ethereum or EVM wallet integrations, or non-DFlow DEX routing.
| File | Kind | Size |
|---|---|---|
| LICENSE | other | 1.0 KB |
| SKILL.md | skill md | 7.0 KB |
| references/browser-sdk.md | markdown | 8.1 KB |
| references/dflow-crypto-trading.md | markdown | 4.9 KB |
| references/dflow-websockets.md | markdown | 4.3 KB |
| references/nft-minting.md | markdown | 4.6 KB |
| references/payments.md | markdown | 5.5 KB |
| references/react-native-sdk.md | markdown | 7.2 KB |
| references/react-sdk.md | markdown | 7.1 KB |
| references/token-gating.md | markdown | 4.9 KB |
| references/transactions.md | markdown | 5.1 KB |
references/browser-sdk.md
View on GitHub# Browser SDK Reference
Complete reference for `@phantom/browser-sdk`.
## Prerequisites
All Phantom Connect integrations require:
1. **Phantom Portal Account** — Register at phantom.com/portal/login
2. **App ID** — Get from Portal (required when using Google or Apple auth providers)
3. **Allowlisted URLs** — Add your domains and redirect URLs in Portal settings
## Auth Providers
| Provider | Description | Requires appId |
| ------------- | ------------------------------- | -------------- |
| `"injected"` | Phantom browser extension | No |
| `"google"` | Google OAuth (embedded wallet) | Yes |
| `"apple"` | Apple ID (embedded wallet) | Yes |
| `"deeplink"` | Phantom mobile app via deeplink | Yes |
Use `"injected"` for extension-only flows (no appId needed). Add `"google"` and/or `"apple"` for social login (requires appId from Phantom Portal). Add `"deeplink"` to support connecting to the Phantom mobile app on devices where the extension is not available.
## Installation
```bash
npm install @phantom/browser-sdk
# For Solana support
npm install @solana/web3.js
```
## Quick Start Template
Generate a project with the Phantom Embedded JS Starter:
```bash
npx -y create-solana-dapp@latest -t solana-foundation/templates/community/phantom-embedded-js
```
## SDK Initialization
### Injected Provider Only (Extension)
```ts
import { BrowserSDK, AddressType } from "@phantom/browser-sdk";
const sdk = new BrowserSDK({
providers: ["injected"],
addressTypes: [AddressType.solana],
});
```
### Multiple Auth Methods
```ts
const sdk = new BrowserSDK({
providers: ["google", "apple", "injected"],
appId: "your-app-id",
addressTypes: [AddressType.solana],
authOptions: {
authUrl: "https://connect.phantom.app/login", // optional
redirectUrl: "https://yourapp.com/callback", // required for OAuth
},
autoConnect: true,
});
```
## Connection
### Basic Connection
```ts
// Connect with specific provider
const { addresses } = await sdk.connect({ provider: "google" });
const { addresses } = await sdk.connect({ provider: "apple" });
const { addresses } = await sdk.connect({ provider: "injected" });
console.log("Connected:", addresses);
// [{ address: "...", addressType: "solana" }]
```
### Auto-Connect
```ts
const sdk = new BrowserSDK({
providers: ["google", "apple"],
appId: "your-app-id",
addressTypes: [AddressType.solana],
autoConnect: true, // Automatically reconnect existing sessions
});
// Or manually trigger
await sdk.autoConnect();
```
### Disconnect
```ts
await sdk.disconnect();
```
## Solana Operations (sdk.solana)
```ts
// Sign message
const { signature, rawSignature } = await sdk.solana.signMessage("Hello Solana!");
// Sign transaction (without sending)
const signedTx = await sdk.solana.signTransaction(transaction);
// Sign and send transaction
const result = await sdk.solana.signAndSendTransaction(transaction);
console.log("TX Hash:", result.hash);
// Network switching
await sdk.solana.switchNetwork("devnet"); // "mainnet-beta", "testnet", "devnet"
// Utilities
const publicKey = await sdk.solana.getPublicKey();
const isConnected = sdk.solana.isConnected();
```
## Auto-Confirm (Injected Provider Only)
```ts
import { NetworkId } from "@phantom/browser-sdk";
// Enable for specific chains
await sdk.enableAutoConfirm({
chains: [NetworkId.SOLANA_MAINNET]
});
// Enable for all supported chains
await sdk.enableAutoConfirm();
// Disable
await sdk.disableAutoConfirm();
// Get status
const status = await sdk.getAutoConfirmStatus();
// Get supported chains
const chains = await sdk.getSupportedAutoConfirmChains();
```
## Extension Detection
```ts
import { waitForPhantomExtension } from "@phantom/browser-sdk";
const isAvailable = await waitForPhantomExtension(5000); // 5s timeout
if (isAvailable) {
console.log("Phantom extension installed");
} else {
console.log("Extension not found - offer OAuth login");
}
```
## Wallet Discovery
Discover all injected wallets using Wallet Standard (Solana):
```ts
// Async discovery
const wallets = await sdk.discoverWallets();
console.log(wallets);
// [
// { id: "phantom", name: "Phantom", icon: "...", addressTypes: [...] },
// { id: "backpack", name: "Backpack", icon: "...", addressTypes: [...] },
// ]
// Get already discovered (sync)
const cachedWallets = sdk.getDiscoveredWallets();
```
## Event Handlers
```ts
// Connection started
sdk.on("connect_start", (data) => {
console.log("Starting:", data.source); // "auto-connect" | "manual-connect"
});
// Connection successful
sdk.on("connect", (data) => {
console.log("Connected:", data.addresses);
console.log("Provider:", data.provider);
});
// Connection failed
sdk.on("connect_error", (data) => {
console.error("Failed:", data.error);
});
// Disconnected
sdk.on("disconnect", (data) => {
console.log("Disconnected");
});
// General errors
sdk.on("error", (error) => {
console.error("SDK Error:", error);
});
// Remove listener
sdk.off("connect", handleConnect);
```
### Events with Auto-Connect
```ts
const sdk = new BrowserSDK({
providers: ["google"],
appId: "your-app-id",
addressTypes: [AddressType.solana],
autoConnect: true,
});
// Set up listeners BEFORE autoConnect triggers
sdk.on("connect", (data) => {
updateUI(data.addresses);
});
sdk.on("connect_error", (data) => {
showLoginButton();
});
await sdk.autoConnect();
```
## Debug Configuration
```ts
import { DebugLevel } from "@phantom/browser-sdk";
// Enable/disable at runtime
sdk.enableDebug();
sdk.disableDebug();
// Set level
sdk.setDebugLevel(DebugLevel.INFO);
// Levels: ERROR (0), WARN (1), INFO (2), DEBUG (3)
// Set callback
sdk.setDebugCallback((message) => {
console.log(`[${message.level}] ${message.category}: ${message.message}`);
});
// Configure all at once
sdk.configureDebug({
enabled: true,
level: DebugLevel.DEBUG,
callback: (msg) => console.log(msg),
});
```
## AddressType Values
| AddressType | Chains |
| ---------------------- | ------------------------ |
| `AddressType.solana` | Mainnet, Devnet, Testnet |
## Supported Solana Networks
| Network | Cluster |
| ------- | ------------ |
| Mainnet | mainnet-beta |
| Devnet | devnet |
| Testnet | testnet |
## Complete Example
```ts
import { BrowserSDK, AddressType, waitForPhantomExtension } from "@phantom/browser-sdk";
// Initialize
const sdk = new BrowserSDK({
providers: ["google", "apple", "injected"],
appId: "your-app-id",
addressTypes: [AddressType.solana],
autoConnect: true,
});
// Set up event handlers
sdk.on("connect", ({ addresses }) => {
document.getElementById("status").textContent = `Connected: ${addresses[0].address}`;
});
sdk.on("connect_error", ({ error }) => {
document.getElementById("status").textContent = `Error: ${error.message}`;
});
// Connect button
document.getElementById("connectBtn").addEventListener("click", async () => {
const hasExtension = await waitForPhantomExtension(2000);
const provider = hasExtension ? "injected" : "google";
await sdk.connect({ provider });
});
// Sign message button
document.getElementById("signBtn").addEventListener("click", async () => {
const { signature } = await sdk.solana.signMessage("Hello!");
console.log("Signature:", signature);
});
// Disconnect button
document.getElementById("disconnectBtn").addEventListener("click", async () => {
await sdk.disconnect();
document.getElementById("status").textContent = "Disconnected";
});
```
## Common Issues
### "appId required" error
Cause: Using `"google"` or `"apple"` provider without providing an appId.
Solution: Register at phantom.com/portal/login, get the App ID, and pass it to the BrowserSDK constructor.
### Redirect not working after OAuth login
Cause: The redirect URL is not allowlisted in Phantom Portal.
Solution: Go to phantom.com/portal/login, open app settings, and add the exact redirect URL (including protocol and path) to the allowlist.
### Phantom extension not detected
Cause: Extension not installed, or detection ran before the extension injected into the page.
Solution: Use `waitForPhantomExtension(5000)` with a timeout. If not found, fall back to social login providers (`"google"` or `"apple"`).
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |