Import a wallet
Privy enables your users to import a private key into their embedded wallet.
This allows users to bring an existing wallet into your application, enabling them to manage their assets directly within your app. For example, a user can import their MetaMask wallet private key to access and manage their assets within your app seamlessly. This method can also be used by developers to migrate users from a different embedded wallet provider to Privy.
Privy’s React SDK currently supports importing wallets on EVM networks and Solana.
Importing a wallet by private key
To have your user import a private key into their embedded wallet, use the importWallet
method from the useImportWallet
hook. As a parameter to this method, pass an object containing the user’s privateKey
as a string
.
If importWallet
succeeds, the imported wallet will be added to the user’s linkedAccounts
and the wallets
array returned by the useWallets
hook, with an imported
field that is marked true
. As an example, you can find the imported wallet like so:
This method will error if the provided private key is not valid or if the user has previously imported a wallet by private key.
Using imported EVM embedded wallets
You can request signatures and transactions from imported wallets using Privy’s native methods, the wallet’s EIP1193 provider, or a third-party library like viem
or ethers
.
Using Privy’s native signature and transaction methods
To use Privy’s native signMessage
, signTypedData
, and sendTransaction
methods with an imported wallet, simply pass the address for the imported wallet as the final optional parameter to these methods:
Using the EIP1193 provider, viem, and ethers
You can also request signatures and transactions from an imported wallet using the wallet’s EIP1193 provider or a library like viem
or ethers
.
To get the EIP1193 provider for the imported wallet, first find the corresponding ConnectedWallet
object from the useWallets
array:
Then, call the object’s getEthereumProvider
method to get an EIP1193 provider for that wallet:
You can then easily pass that EIP1193 provider to a library like viem
or ethers
to use those libraries’ interfaces to send requests to the wallet.
Using imported Solana embedded wallets
You can request signatures and send transactions using your imported Solana wallet just like with regular embedded Solana wallets.
Then, call the object’s signMessage
method to sign.
Exporting imported embedded wallets
Privy enables your users to export the full private key for their embedded wallet, even if it was imported. This allows them to use their embedded wallet address with another wallet client, such as MetaMask in any application.
To have your user export their embedded wallet’s private key, use the exportWallet
method from the usePrivy
hook. As a parameter to this method, you must pass an object containing an address
field with the user’s imported wallet address as a string
.
As an example, you might have an export wallet button in your app like so:
Exporting the seed phrase for an imported embedded wallet is not supported, as it is impossible to recover the full seed phrase for the wallet from the imported private key.
Was this page helpful?