Appearance
Recovering the wallet on a new device
When a user uses their embedded wallet on a new device for the first time, the wallet must first be recovered on that device. Solana embedded wallets can be recovered automatically using the Privy Expo SDK, but you can also set up alternative recovery methods like a passcode or Cloud backup.
TIP
If a user recovers any of their embedded wallets (on any chain, or with any HD index), it will automatically provision all of their embedded wallets on that device
Recovering the wallet
To recover an embedded Solana wallet for your user, use the recover
function returned by the Privy Expo SDK's useRecoverEmbeddedWallet
hook. View the wallet recovery guide for more information about the parameters that can get passed to this method
INFO
If the wallet is on automatic recovery ('privy'
), the wallet will be automatically recovered when calling getProvider()
.
tsx
import {
useEmbeddedSolanaWallet,
useRecoverEmbeddedWallet,
needsRecovery,
getUserEmbeddedSolanaWallet,
usePrivy,
} from '@privy-io/expo';
const CreateWalletButton = () => {
const [password, setPassword] = useState('');
const solanaWallet = useEmbeddedSolanaWallet();
const {recover} = useRecoverEmbeddedWallet();
const {user} = usePrivy();
const account = getUserEmbeddedSolanaWallet(user);
if (needsRecovery(solanaWallet) && account.recovery_method === 'user-passcode') {
return (
<View>
{/* Make sure to handle sensitive information appropriately */}
<TextInput value={password} onChangeText={setPassword} />
<Button
onPress={async () => {
await recover({
// Other recovery methods include 'google-drive' and 'icloud'
recoveryMethod: 'user-passcode',
password,
});
await solanaWallet.getProvider(); // Connect to the wallet after recovery
}}
>
Recover Wallet
</Button>
</View>
);
}
return null;
};