Export Private Key
This allows them to use their embedded wallets address with another wallet client, such as Metamask in any application. Note that this embedded wallet is only controlling the smart account and does not hold assets in it. If you want to simply transfer ownership to a Metamask and interact with a smart contract, we'll recommend checking the transfer ownership section.
To have your user export their embedded wallet's private key, use the exportPrivateKey
method from the SDK.
If your user is not authenticated
or has not yet created an embedded wallet in your game, this method will fail.
As an example, you might attach exportPrivateKey
as an event handler to an export wallet button in your app:
ExportWalletButton.tsx
import openfort from "./openfortConfig"
// This example assumes you have already checked that Openfort 'embeddedState' is
// `ready` and the user is `authenticated`
function ExportWalletButton() {
const handleExportWalletButton = async () => {
const privateKey = await openfort.embeddedWallet.exportPrivateKey();
console.log(privateKey);
};
return (
<button onClick={handleExportWalletButton}>
{'Export my wallet'}
</button>
);
}