Introduction
Phantom's Wallet SDKs provide a family of client and server libraries to integrate Phantom wallet functionality into web and mobile applications. Whether you're building a DApp on Solana, adding Ethereum provider support, or embedding wallet flows into native apps, Phantom supplies modular, well-documented SDKs: Browser SDK, Wallet Adapter integrations, React / React Native components, and server-side tools.
Why choose Phantom's Wallet SDKs?
Phantom focuses on secure user-controlled wallets, simplicity for developers, and cross-chain reach. These SDKs abstract provider detection, connection UX, signing flows, and chain-specific edge cases, letting you focus on product logic instead of wallet plumbing.
SDK types & short descriptions (H2)
Browser SDK (H3)
The Browser SDK offers a lightweight JS interface to detect the Phantom provider injected into the browser extension or mobile web context. It handles provider negotiation (e.g. `window.phantom`), session/connect flows, and exposes methods for signing and sending transactions while keeping private keys strictly in the user's wallet.
Key features (H4)
- Provider detection & EIP-1193-compatible API
- Connect / disconnect UX helpers
- Transaction signing without key custody
- Chain-aware provider methods
React SDK & React UI (H3)
For React apps, Phantom provides hooks and wrapped UI components that minimize integration time. Use the React SDK for programmatic control and React UI if you want pre-built modals and UX patterns that follow Phantom's guidelines.
Why use the React layer (H4)
Hooks automatically subscribe to provider events (account change, network change), simplify reacquiring sessions, and integrate cleanly with state management libraries. The UI kit speeds up adoption with tested modal flows for connecting and approving transactions.
React Native SDK (H3)
Phantom's React Native SDK and demo apps make it straightforward to integrate wallets in mobile applications. The SDK is designed to work with deep links or wallet-to-app protocols to handle signing requests.
Server SDK (H3)
When you need a server-controlled wallet (for custodial workflows, relayers, or programmatic signing), the Server SDK offers key-management and transaction-sending utilities. These should be used with strong server-side security and HSM-backed key protection.
Integration patterns & recommended flows
There are three common integration patterns: (1) Browser-first dApp that interacts with a user wallet (non-custodial), (2) Mobile-first using React Native + deep links / wallet adapter, and (3) Backend services with server-side wallets or relayers. Each pattern has trade-offs in UX and security.
Typical connect flow (H3)
- Detect provider (e.g. `window.phantom` or Wallet Adapter).
- Call `connect()` — the wallet prompts the user to approve.
- Store ephemeral session info (public key, chain ID) in client state.
- Sign transactions or messages via the provider.
- Send signed transactions to RPC nodes or your backend relayer.
// minimal provider detection (Browser SDK)
if (typeof window !== 'undefined' && window.phantom?.solana?.isPhantom) {
const provider = window.phantom.solana;
await provider.connect();
const publicKey = provider.publicKey.toString();
console.log('Connected:', publicKey);
}
Security best practices (H2)
Security is paramount when dealing with wallets. The primary rule: **never** handle or persist private keys in client-side code. Use in-wallet signing and keep sensitive server roles behind HSMs and strong access controls.
Client-side guidance (H3)
- Do not store private keys or mnemonic phrases.
- Validate transaction requests on your server before prompting users.
- Surface clear UX for what permission is being requested (sign, send, connect).
Server-side guidance (H3)
- Use hardware-backed key stores or cloud KMS (AWS KMS, GCP KMS).
- Audit logs of signing operations and rate-limit signing endpoints.
- Separate roles: one system to build raw transactions, another to sign them.
Browser SDK: example quickstart (H2)
Use `@phantom/browser-sdk` or the `@phantom/wallet-sdk` packages to interact with Phantom. The snippet below is a canonical connect + sign example for a web app.
// Example: connect + sign (high level)
async function connectAndSign(message) {
const provider = window.phantom?.ethereum || window.phantom?.solana;
if (!provider) throw new Error('Phantom provider not found');
await provider.request({ method: 'eth_requestAccounts' }); // or provider.connect()
const signature = await provider.request({ method: 'personal_sign', params: [message, provider.selectedAddress] });
return signature;
}
React Native & mobile integration (H2)
Mobile requires handling app-to-app flows. Use the React Native SDK (or Wallet Adapter mobile flavors) and follow platform guidelines for deep linking, callback URIs, and fallback to in-app browser flows. Phantom's GitHub contains demo apps that show patterns for both iOS and Android.
Practical tips (H4)
- Implement robust state reconciliation after returning from a deep link (user may cancel on wallet side).
- Use universal links/intent filters to provide a smooth UX.
- Test on physical devices across networks and NFC/intent variations.
Wallet Adapter & multi-wallet support (H2)
If you support multiple wallets (e.g., Phantom plus other Solana wallets), consider using the Solana Wallet Adapter ecosystem which provides a standardized adapter interface and UI components. Adapter integration reduces duplicate code and centralizes wallet-selection logic.
Testing & developer tooling (H2)
Local testing often requires mock providers or testnets. Phantom's docs and GitHub repositories include demo apps and "early-access" packages for testing. Use testnets (Devnet/Testnet) and provider sandboxing to validate flows before mainnet deployment.
Example: mocking a provider in tests (H3)
// Jest pseudo-mock example
global.window = Object.create(window);
Object.defineProperty(window, 'phantom', { value: { solana: { isPhantom: true, connect: jest.fn(), request: jest.fn() } } });
FAQ & troubleshooting (H2)
Why doesn't the provider appear in my app? (H3)
Common reasons: extension not installed, blocked by browser privacy settings, or the page is loaded inside a restricted webview. Ensure Phantom extension/app is installed and that your app runs in a context that allows injected providers. For iOS in-app webviews, prefer opening an external browser or using an SDK-backed mobile flow.
What about cross-chain (Ethereum, Bitcoin, Polygon)? (H3)
Phantom now supports multiple chains. The provider API exposes chain-aware methods; check the provider docs for chain-specific nuances (e.g., EIP-1193 for Ethereum-like behavior and Solana-specific transaction formats).
Conclusion
Phantom's Wallet SDK suite is designed to meet diverse integration needs: small web apps, enterprise backends, multi-wallet apps, and mobile-first experiences. Prioritize secure signing patterns, use the right SDK for your platform, and leverage Phantom's React/UI components when you want fast, polished UX.