Skip to content

Creating Solana wallets

With Privy, you can create Solana wallets for your users automatically on login, manually from your frontend, or via wallet pregeneration from your server before they have even logged in.

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.solana.createOnLogin property of your PrivyProvider:

tsx
<PrivyProvider
  appId="your-privy-app-id"
  config={{
    embedded: { 
      solana: { 
        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 creation

To create an embedded Solana wallet for your user, use the create method of the wallet interface returned by the useEmbeddedSolanaWallet hook. Do not pass any parameters to the method.

Users may only have one embedded Solana wallet currently. To check if your user already has an embedded Solana wallet, pass the wallet interface to Privy's isNotCreated method.

Below is an example of creating a wallet only for users who do not already have a wallet.

tsx
import {useEmbeddedSolanaWallet, isNotCreated} from '@privy-io/expo';

const WalletButton = () => {
  const wallet = useEmbeddedSolanaWallet();

  if (isNotCreated(wallet)) {
    return <Button onPress={() => wallet.create()}>Create Wallet</Button>;
  }

  return <p>{wallet.publicKey}</p>;
};

Pregenerating Solana wallets

With Privy, you can pregenerate self-custodial Solana embedded wallets associated with a given account, like an email address or phone number, without requiring the user to login. You can even send assets to the wallet before the user logs in to your app for the first time.

Follow the embedded wallet pregeneration guide to create Solana wallets for your users.

Once the user associated with the account logs in, they will be able to access the pregenerated wallet and any assets sent to them.