Installation
Usage
- JavaScript
- React
Call
addPhantomRedirectSolanaExtension once during app initialization, passing the current URL so
the extension can detect and complete any in-progress Phantom redirect:Parameters
| Parameter | Type | Description |
|---|---|---|
url | URL (optional) | The current page URL. Used to detect and complete a pending Phantom redirect. Pass new URL(window.location.href) on every page load. |
onCloseTab | () => void (optional) | Callback invoked when the redirect tab should close itself. By default, the SDK calls window.close(). Provide a custom handler if you need different behavior (e.g. navigating to a fallback route). |
disableAutoRedirectCompletion | boolean (optional) | When true, the extension will not automatically detect and complete pending redirects on load. Defaults to false. |
client | DynamicClient (optional) | The Dynamic client instance. Only required when using multiple clients. |
How it works
Phantom’s redirect protocol works as follows:- Your app calls a standard wallet operation (connect, sign, send, disconnect) on the Phantom redirect provider
- The SDK builds an encrypted deep link and redirects the user to the Phantom mobile app
- The user approves the request inside Phantom
- Phantom redirects back to your app. For connect and sign operations, the redirect URL includes an encrypted response. For disconnect, Phantom redirects back with no query parameters.
- On the next page load,
addPhantomRedirectSolanaExtensiondetects the redirect, decrypts the response (if present), and completes the operation
onCloseTab callback.
All payloads between your app and Phantom are encrypted end-to-end using NaCl box encryption with
ephemeral key pairs.
Supported operations
Once registered, the Phantom redirect provider supports all standard Solana wallet operations:connect— request wallet connectiondisconnect— end the wallet sessionsignMessage— sign an arbitrary messagesignTransaction— sign a transactionsignAllTransactions— sign multiple transactionssignAndSendTransaction— sign and submit a transaction
Connect and verify on mobile
On mobile,connectAndVerifyWithWalletProvider triggers two sequential deep links — one to connect
and another to sign for verification. iOS will not honor the second deep link because it is no longer
tied to a user gesture. Android may handle this differently, but this restriction applies to all
mobile platforms to ensure a stable experience and prevent production-only errors.
Instead, use connectWithWalletProvider and verifyWalletAccount as two separate user actions:
connectAndVerifyWithWalletProvider and fall back to
the two-step flow:
Setting a redirect URL
Phantom redirects back to your app after the user approves or rejects a request. Make sure your app handles the redirect URL on the page that callsaddPhantomRedirectSolanaExtension, so the extension
can complete the pending operation automatically.
Limitations
- Requires the user to have the Phantom mobile app installed
- The redirect flow causes a full page navigation — ensure your app state is restored on return
- Each operation generates a new ephemeral encryption key pair; sessions do not persist across devices
- Only supported on Solana
connectAndVerifyWithWalletProvideris not supported on mobile — see Connect and verify on mobile above
Related functions
- addSolanaExtension - Register standard Solana wallet providers
- Connecting and Verifying a Wallet - Connect and verify wallet accounts
- signing-sending-transactions - Sign and send transactions with any Solana wallet