Creating multiple HD wallets
To create multiple HD wallets for a user, use thecreateWallet
method:Creating the user’s first wallet
If this is the first wallet you are creating for the user (e.g. the 0th index), you may callcreateWallet
with no parameters:Creating additional wallets
There are two approaches to creating additional wallets.1. Create an additional wallet with the next available index
If the user already has an embedded wallet, and you are creating an additional embedded wallet, callcreateWallet
with createAdditional
set to true
:If
true
, will allow the user to create a wallet regardless if it is their first wallet or an
additional wallet. If false
, createWallet will succeed only if the use is creating their first
wallet. Defaults to false
.createWallet
will return a Promise that resolves to the Wallet
created for the user at the specified index, if it was successful. This method will reject with an error if:- the user is not
authenticated
- the user already has an embedded wallet and
createAdditional
was not set totrue
- if there is another error during wallet creation, such as the user exiting prematurely
2. Create an additional wallet with a specified HD wallet index
To create a wallet at a specified HD wallet index, callcreateWallet
with the preferred walletIndex
.
This method will either create a new wallet, or return the existing one if one already exists at the specified index.The specified HD wallet index. Must be a positive number, and must be
0
for the user’s first
wallet.A wallet with HD index 0 must be created before creating a wallet at greater HD indices.
- the user is not
authenticated
- wallet creation fails or the wallet cannot be added to the user’s account.
- an invalid HD wallet index is supplied, i.e.
walletIndex
is less than 0, or ifwalletIndex
is greater than 0 while user has no wallet with HD index 0.
Using multiple HD wallets
Getting a specific embedded wallet
Once a user has one or more embedded wallets, the wallets are added to bothlinkedAccounts
array of the user
object and the array of connected wallets returned by useWallets
.To find a specific embedded wallet for the user, search the useWallets
array for a wallet with walletClientType: 'privy'
and an address
that matches your desired address:useWallets
array for entries with walletClientType: 'privy'
:Requesting signatures and transactions
Your app can then use Privy’s native signature and transaction methods, the wallet’s EIP1193 provider, or a third-party library likeviem
or ethers
, per the instructions below.Using Privy’s native signature and transaction methods
To use Privy’s nativesignMessage
, signTypedData
, and sendTransaction
methods with a specific embedded wallet, simply pass the address for your desired wallet as the final optional parameter to these methods:Using the EIP1193 provider, viem, and ethers (EVM only)
You can also request signatures and transactions from a specific embedded wallet using the wallet’s EIP1193 provider or a library likeviem
or ethers
.To get the EIP1193 provider for a specific embedded wallet, first find the corresponding ConnectedWallet
object from the useWallets
array:getEthereumProvider
method to get an EIP1193 provider for that wallet:viem
or ethers
to use those libraries’ interfaces to send requests to the wallet.Exporting HD wallets
To export the private key for a specific HD wallet, simply pass the address of the wallet you’d like to export as anaddress
parameter to the exportWallet
method:address
is passed to exportWallet
, Privy will default to exporting the non-imported wallet at walletIndex: 0
.Pregenerating multiple HD wallets (EVM only)
Privy supports pregenerating multiple HD wallets in Ethereum when creating new users. With our user import endpoint, you can create a user with up to 10 pregenerated HD wallets. Simply call the import endpoint withcreate_n_ethereum_wallets
set to the number of embedded wallets you want to generate for your user.Pregeneration endpoints have heavier rate limit of 240 users per minute. If you are being rate
limited, responses will have status code 429. We suggest you setup exponential back-offs starting
at 1 second to seamlessly recover.