Appearance
Creating an embedded wallet
If your app uses embedded wallets, you can configure Privy to create wallets automatically for your users as part of their login flow, or you can manually create wallets for your users when required.
Automatic wallet creation
When automatic wallet creation is enabled, Privy will create wallets for users when they login to your app––specifically, as part of Privy's login
method.
To configure Privy to automatically create embedded wallets for your user when they login, set the config.embedded.ethereum.createOnLogin
or config.embedded.solana.createOnLogin
property of your PrivyProvider
:
tsx
<PrivyProvider
appId="your-privy-app-id"
config={{
embedded: {
ethereum: {
createOnLogin: 'users-without-wallets', // defaults to 'off'
},
},
}}
>
{children}
</PrivyProvider>
The possible values for createOnLogin
are 'off'
, 'users-without-wallets'
, and 'all-users'
:
- When
'off'
, Privy will not automatically create embedded wallets for your users, but you can always manually create wallets for them later. This is the default setting. - When set to
'users-without-wallets'
, Privy will automatically create an embedded wallet for users that do not already have another external wallet linked to their account. - When set to
'all-users'
, Privy will automatically create an embedded wallet for all users, including those that do have another external wallet linked to their account.
Manual wallet creation
To manually create an embedded wallet for your user, use the Privy Expo SDK's useEmbeddedEthereumWallet
hook.
The useEmbeddedEthereumWallet
will give you access to a create
method that can be used to create new ethereum wallets on the currently logged in user.
TIP
By default, wallets are automatically recoverable on new devices once users log in. You can upgrade the recovery method used for a user-owned recovery method (such as a passcode), by following this guide.
tsx
import {useEmbeddedEthereumWallet} from '@privy-io/expo';
const CreateWalletButton = () => {
const {wallets, create} = useEmbeddedEthereumWallet();
if (wallets.length === 0) {
return <Button onPress={() => create()}>Create Wallet</Button>;
}
return null;
};
By default, users can have at most one embedded wallet on EVM networks. If you need support for additional embedded wallets, your app can create additional hierarchical deterministic (HD) wallets by following this guide.
How can my app know if a user already has an embedded wallet?
To determine if the current user already has an embedded wallet, you can either:
- obtain an object representation of the user from the Privy SDK's
usePrivy
hook, and check if it includes a wallet with awalletClientType
of'privy'
, or - use the Privy client's
useEmbeddedEthereumWallet
hook, like below:
tsx
import {useEmbeddedEthereumWallet, isConnected} from '@privy-io/expo';
const Component = () => {
const {wallets} = useEmbeddedEthereumWallet();
const [password, setPassword] = useState('');
if (wallets.length > 0) {
/* The user's embedded wallet exists and is ready to be used! */
return <View>Wallet Exists</View>;
}
return null;
};