Skip to main content
Some setups may benefit from apps being able to securely export and cache a wallet’s private key locally for the user’s benefit. This is typically relevant for apps requiring ultra-low latency (and therefore no server roundtrip). For such use cases, Privy enables your app to programmatically export a wallet’s private key without showing a modal, use the getWalletPrivateKey method from the useGetWalletPrivateKey hook.
Programmatic export is a security-sensitive operation. It requires incredible care, and may have impact on your app’s custody.Contact Privy Support to enable this feature for your product.
This method returns the private key encrypted using HPKE (Hybrid Public Key Encryption). Your app provides its own P-256 public key and receives the encrypted private key which must be decrypted client-side.
Programmatic export is only supported for TEE-based wallets. On-device wallet environments do not support this feature. Learn more.

Usage

The getWalletPrivateKey method accepts an object with the following parameters:
address
string
required
The address of the embedded wallet to export.
recipientPublicKey
string
required
Base64-encoded SPKI P-256 public key. The private key will be encrypted to this public key using HPKE.

Returns

Returns a Promise for an EncryptedWalletKey object:
ciphertext
string
Base64-encoded HPKE ciphertext containing the encrypted private key.
encapsulatedKey
string
Base64-encoded HPKE encapsulated key needed for decryption.
chainType
'ethereum' | 'solana'
The chain type of the exported wallet.

Example

The returned key format depends on the chain type:
  • Ethereum: Hex-encoded key (e.g., 0x... or without prefix)
  • Solana: Base58-encoded key
To decrypt the exported key, use the HPKE decryption implementation shown in the REST API tab.

Errors

The method throws a PrivyClientError in the following cases: