Skip to content

Pregenerating an embedded wallet for new users

With Privy, you can pregenerate self-custodial Ethereum and Solana embedded wallets while creating a new user with other login methods, 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.

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

Using @privy-io/server-auth

To pregenerate embedded wallets for a given user, use the PrivyClient's importUser method.

tsx
const user = await privy.importUser({
  linkedAccounts: [
    {
      type: 'email',
      address: '[email protected]',
    },
  ],
  createEthereumWallet: true,
  createSolanaWallet: true,
  createEthereumSmartWallet: true,
  customMetadata: {
    username: 'name',
    isVerified: true,
    age: 23,
  },
});

As a parameter to the method, pass an ImportUserInput object with the following fields:

FieldTypeDescription
linkedAccountsLinkedAccount[]An array including all of the user's linked accounts.

These objects are in the same shape as the linked accounts returned by getUser. For each linked account, you must specify the type and must not include a verifiedAt timestamp.
createEthereumWalletboolean(Optional) Whether to pregenerate an Ethereum embedded wallet for the imported user. Defaults to false. You must set this to true to create an Ethereum wallet.
createSolanaWalletboolean(Optional) Whether to pregenerate a Solana embedded wallet for the imported user. Defaults to false. You must set this to true to create a Solana wallet.
createEthereumSmartWalletboolean(Optional) Whether to pregenerate a smart wallet for the imported user. Defaults to false. You must set this to true to create a smart wallet. If createEthereumSmartWallet is true, you must also explicitly set createEthereumWallet to true as well. Learn more about smart wallets here!

| customMetadata | CustomMetadataType | (Optional) Custom metadata to associate with the user. |

This will pregenerate an embedded/smart wallet that can be accessed by logging into the imported account (e.g. [email protected] in the example above).

Using the REST API

To pregenerate embedded wallets, simply make a POST request to Privy's import user API:

sh
https://auth.privy.io/api/v1/users

In the body of the request:

FieldTypeDescription
linked_accountsarrayAn array that contains the user's account to claim the wallet.
create_ethereum_walletbooleanWhether to create an Ethereum embedded wallet. Set to true to create one. You must set this to true to create an Ethereum wallet.
create_solana_walletbooleanWhether to create a Solana embedded wallet. Set to true to create one. You must set this to true to create a Solana wallet.
create_ethereum_smart_walletbooleanWhether to create a smart wallet. Set to true to create one. You must set this to true to create a smart wallet. If create_ethereum_smart_wallet is true, you must also explicitly set create_ethereum_wallet to true as well. Learn more about smart wallets here!
custom_metadataobject(Optional) Custom metadata to associate with the user.

Below is a sample cURL command for generating a new wallet for a user with Privy:

sh
$ curl --request POST https://auth.privy.io/api/v1/users \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H "Content-Type: application/json" \
-d '{
  "create_ethereum_wallet": true,
  "linked_accounts": [
    {
      "address": "[email protected]",
      "type": "email"
    }
  ]
}'

A successful response will include the new user object along with their user ID and embedded wallet address, like below:

json
{
  "id": "did:privy:clddy332f002tyqpq3b3lv327",
  "created_at": 1674788927,
  "linked_accounts": [
    {
      "address": "[email protected]",
      "type": "email"
    },
    {
      "address": "0x3DAF84b3f09A0E2092302F7560888dBc0952b7B7",
      "type": "wallet",
      "walletClient": "privy",
      "chain_type": "ethereum"
    }
  ]
}

Accessing a pregenerated wallet

A user can easily claim their pregenerated wallet simply by logging into your app with one of their linked accounts.