Introduction
This guide will help you use the Phantom redirect-based connect feature on mobile. Instead of deeplinking into the Phantom in-app browser, your users can enjoy a redirect-based connection, where they are automatically redirected between the app and their wallet to facilitate the connect, sign and additional method calls.Why redirect events are necessary
Unlike browser-extension wallets (like MetaMask or Phantom browser extension), Phantom on mobile operates via deep links. When you request a signature:- Your app opens Phantom via a deep link (
phantom://) - User approves or rejects in the Phantom app
- Phantom redirects back to your app
- The original JavaScript execution context is lost
- Any
Promiseawaiting the signature result never resolves - Your app loses track of the pending operation
Setup
mobileExperience prop
Make sure you set mobileExperience to redirect on your DynamicContextProvider:
- React
signAndSendTransaction) and access the result, read on.
Handling redirect events
When using redirect-based signing on mobile, Phantom opens via deep link and redirects back after the user approves or rejects. Because the original Promise context is lost, you must use event listeners to capture the results.- React
- React Native
Use the Mount this hook in a component that renders when your app loads so it can capture the redirect result.
usePhantomRedirectEvents hook to listen for redirect results:Available events
| Event / Callback | Payload | Description |
|---|---|---|
signMessageResult / onSignMessage | { signature?, message?, requestId?, errorCode?, errorMessage? } | Fired after signing a message. |
signTransactionResult / onSignTransaction | { transaction?, requestId?, errorCode?, errorMessage? } | Fired after signing a single transaction. |
signAndSendTransactionResult / onSignAndSendTransaction | { signature?, transaction?, requestId?, errorCode?, errorMessage? } | Fired after signing and broadcasting a transaction. |
signAllTransactionsResult / onSignAllTransactions | { transactions?, requestId?, errorCode?, errorMessage? } | Fired after signing multiple transactions. |