Skip to main content
With Privy, you can pregenerate self-custodial Ethereum and Solana wallets for existing users, or create 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. Wallet pregeneration is useful for:
  • Airdrops and rewards: Distribute tokens or NFTs to users before they sign up
  • Web2 to web3 migrations: Import existing users from a database and provision wallets for them
  • Frictionless onboarding: Allow users to receive assets before creating an account
  • Server-side provisioning: Generate wallets programmatically based on off-chain events or criteria
This recipe covers three scenarios: creating wallets for new users, adding wallets to existing users, and batch importing users with wallets.

Pregenerating wallets for new users

Create new users with pregenerated wallets in a single operation. This is useful for airdrops, migrations, or any scenario where wallets need to exist before authentication.
  • NodeJS
  • NodeJS (server-auth)
  • Java
  • REST API
To pregenerate embedded wallets for a new user, use the create method on the users() interface of the Privy client.

Usage

const privy = new PrivyClient({ appId: 'your-app-id', appSecret: 'your-app-secret' });

const user = await privy.users().create({
    linked_accounts: [
        {
            type: 'email',
            address: '[email protected]',
        },
    ],
    wallets: [
        {
            chain_type: 'ethereum',
            wallet_index: 0,
            additional_signers: [
                {
                    signer_id: '<signer-id>',
                    // Policies specific to this signer
                    override_policy_ids: ['<policy-id>']
                }
            ],
            // Policies for all transactions on the wallet, no matter the signer
            policy_ids: ['<policy-id>']
        },
        {
            chain_type: 'solana',
            wallet_index: 0,
            additional_signers: [
                {
                    signer_id: '<signer-id>',
                    override_policy_ids: ['<policy-id>']
                }
            ],
            policy_ids: []
        }
    ],
    create_direct_signer: true
});

Params and returns

Check out the API reference for more details.

Creating wallets for existing users

Add additional embedded wallets to users who already have Privy accounts. This is useful when expanding to support new chains or creating wallets based on in-app actions.
  • NodeJS
  • NodeJS (server-auth)
  • REST API
To create embedded wallets for an existing user, use the pregenerateWallets method from the users() interface of the Privy client.

Usage

const user = await privy.users().pregenerateWallets('did:privy:clddy332f002tyqpq3b3lv327', {
    wallets: [
        {
            chain_type: 'ethereum',
            wallet_index: 0,
        },
        {
            chain_type: 'solana',
            wallet_index: 0,
        }
    ],
    create_direct_signer: true
});
Check out the API reference for more details.

Batch importing users with wallets

Import multiple users with pregenerated wallets in a single batch operation. This is more efficient than creating users individually when provisioning wallets for hundreds or thousands of users at once.
  • REST API
To batch import multiple users with pregenerated wallets, make a POST request to https://auth.privy.io/api/v1/apps/<your-app-id>/users/import.

Usage

Below is a sample cURL command for batch importing users with pregenerated wallets:
$ curl --request POST https://auth.privy.io/api/v1/apps/<your-privy-app-id>/users/import \
-u "<your-privy-app-id>:<your-privy-app-secret>" \
-H "privy-app-id: <your-privy-app-id>" \
-H "Content-Type: application/json" \
-d '{
    "users": [
        {
            "linked_accounts": [
                {
                    "address": "[email protected]",
                    "type": "email"
                }
            ],
            "wallets": [
                {
                    "chain_type": "ethereum",
                    "wallet_index": 0,
                    "policy_ids": ["<policy-id>"],
                    "additional_signers": [
                        {
                            "signer_id": "<signer-id>",
                            "override_policy_ids": ["<policy-id>"]
                        }
                    ]
                }
            ],
            "create_direct_signer": true
        },
        {
            "linked_accounts": [
                {
                    "address": "[email protected]",
                    "type": "email"
                }
            ],
            "wallets": [
                {
                    "chain_type": "solana",
                    "wallet_index": 0
                }
            ],
            "create_direct_signer": false
        }
    ]
}'
A successful response will include an array of the newly created users with their wallet addresses:
{
    "users": [
        {
            "id": "did:privy:abc123",
            "created_at": 1674788927,
            "linked_accounts": [
                {
                    "address": "[email protected]",
                    "type": "email"
                },
                {
                    "address": "0x3DAF84b3f09A0E2092302F7560888dBc0952b7B7",
                    "type": "wallet",
                    "wallet_client": "privy",
                    "chain_type": "ethereum"
                }
            ]
        },
        {
            "id": "did:privy:def456",
            "created_at": 1674788928,
            "linked_accounts": [
                {
                    "address": "[email protected]",
                    "type": "email"
                },
                {
                    "address": "9KnvxKTx...",
                    "type": "wallet",
                    "wallet_client": "privy",
                    "chain_type": "solana"
                }
            ]
        }
    ]
}

Parameters

users
UserImportRequest[]
required
An array of user objects to import. Each object has the following fields:

What happens when users log in

When users log in for the first time after wallets have been pregenerated, the wallets automatically appear in their account. Users can immediately access these wallets and any assets that were sent to them. These wallets work identically to wallets created during login. Users can sign transactions, view balances, and manage their assets through the standard application interface.