Importing user data
You can easily create users and their accounts with Privy and can even pre-generate Privy embedded wallets for them. Privy supports both:- just-in-time migration so you can map your existing users to new Privy users as they log in
- proactive migration to import user data into Privy all at once
Just-in-time migration
The simplest option is to “lazily” transfer your existing users to Privy. When an existing user logs in to your app via Privy for the first time, add their Privy DID to your internal users database to create a mapping between your existing user entry and their Privy user object. Namely, we suggest:- In your internal users database, add a
PrivyDID
column. - In the
onComplete
callback from Privy’suseLogin
hook, if theisNewUser
flag istrue
, make a request to your backend with the user’s Privy DID (user.id
) and any account data you need to identify that user from your existing DB.
- When your backend receives the request from step (2), find the corresponding entry in your internal user database, matching on their wallet address, email address, or any other relevant account data.
1
If entry does not have a
PrivyDID
, add the Privy DID from your request to the PrivyDID
column in your database.2
If the entry already has a “Privy DID” in your database, it should match the Privy DID included
in your request. There is nothing more to do.
3
If there is no user matching the account information in the request, you can assume it is a new
user in your internal database, and create an entry for them with their
PrivyDID
.Proactive migration
If your existing users database associates multiple linked accounts (e.g. email, wallet, Discord, etc.) to a single user, we recommend that you proactively migrate them to Privy using the create a batch of users endpoint. This ensures you can migrate your users and preserve the links between their different accounts in Privy. Please see the instructions here for more.Ensuring continuous asset ownership
Once you’ve migrated your user data to Privy, you should next migrate user assets if necessary to ensure the transition is seamless for your users. This can be done by transferring over user addresses to Privy (migrating the wallet) or having them transfer assets to their new accounts (migrating the assets). The best path depends on your current setup and whether you need users to keep their existing wallets. We generally recommend transferring assets if you can.In most cases, migrating assets and/or wallets is only necessary if you are coming from another
embedded wallet provider. If your users currently use external wallets to store their assets,
you can simply import their address to Privy.
If you are able to transfer assets
Migrating from a custodial system
Migrating from a custodial system
If you are able to submit transactions on behalf of your users, you can set up batch
transactions on your backend, sponsoring gas on behalf of your users to transfer their assets
into pregenerated Privy wallets.
Migrating from a non-custodial system
Migrating from a non-custodial system
When they next log in, prompt your users to run a one-time transfer to migrate their assets over
to their new account.
If you need to transfer wallets instead of transferring assets
Migrating from a custodial system (where you have access to user keys)
Migrating from a custodial system (where you have access to user keys)
You can import user keys to Privy easily if you have access to them. This enables you to
smoothly move your users’ keys so they are managed by Privy’s non-custodial system.
Migrating from a non-custodial system
Migrating from a non-custodial system
We recommend you prompt your user to export their keys so they can use them with an external
wallet (like MetaMask).
Privy’s system is non-custodial. This means neither you nor Privy will have any access to your
user’s private keys after the migration.