Phantom Browser SDK

The Phantom Browser SDK provides a framework-agnostic JavaScript/TypeScript interface for integrating Phantom wallet functionality into web applications, supporting both browser extension and embedded wallet types.

Features

  • Framework Agnostic: Works with vanilla JavaScript/TypeScript and any web framework
  • Multi-Chain Support: Solana, Ethereum, Bitcoin, and Sui networks
  • Native Transaction Support: Direct transaction object handling
  • Multiple Provider Types: Browser extension and embedded wallets
  • TypeScript Support: Full TypeScript definitions included

Security

The Browser SDK uses IndexedDB with non-extractable crypto keys for secure key storage. This approach ensures:
  • Private keys never leave the user’s browser
  • Keys are stored using Web Crypto API with non-extractable properties
  • Hardware-backed security when available
  • User maintains full control of their assets

Installation

npm install @phantom/browser-sdk

Quick Start

Injected Provider (Browser Extension)

import { BrowserSDK } from "@phantom/browser-sdk";

// Initialize SDK for browser extension
const sdk = new BrowserSDK({ 
  providerType: "injected" 
});

const result = await sdk.connect();
console.log("Connected:", result.addresses);

Embedded Provider

import { BrowserSDK, AddressType } from "@phantom/browser-sdk";

// Initialize SDK for embedded wallet
const sdk = new BrowserSDK({
  providerType: "embedded",
  addressTypes: [AddressType.solana, AddressType.ethereum],
  organizationId: "your-organization-id",
  apiBaseUrl: "https://api.phantom.app/v1/wallets"
});

// Connect and create wallet
try {
  const { walletId, addresses } = await sdk.connect();
  console.log("Wallet ID:", walletId);
  console.log("Connected addresses:", addresses);
} catch (error) {
  console.error("Connection failed:", error);
}

Configuration Options

OptionTypeRequiredDescription
providerType"injected" | "embedded"YesConnection method
addressTypesAddressType[]Embedded onlySupported networks
organizationIdstringEmbedded onlyYour organization ID
apiBaseUrlstringEmbedded onlyAPI endpoint URL

Core Methods

connect()

Establish connection with Phantom wallet:
const result = await sdk.connect();
// Returns: { addresses: {...}, walletId?: string }

getAddresses()

Retrieve connected wallet addresses:
const addresses = await sdk.getAddresses();
// Returns: WalletAddress[] - array of address objects

signMessage()

Sign arbitrary messages:
const signature = await sdk.signMessage({
  message: "Hello from my app!",
  address: "wallet_address_here"
});

signAndSendTransaction()

Sign and broadcast transactions:
const result = await sdk.signAndSendTransaction({
  transaction: transactionObject,
  address: "wallet_address_here"
});

disconnect()

End wallet session:
await sdk.disconnect();

Supported Networks

  • Solana: Mainnet, Devnet, Testnet
  • Ethereum: Mainnet, Sepolia
  • Bitcoin: Mainnet, Testnet
  • Sui: Mainnet, Testnet, Devnet
  • Polygon, Arbitrum, Base

Next Steps