# Importing a wallet from a private key

Use `openfort.embeddedWallet.import(...)` to register an existing private key as a new embedded wallet. The flow is identical to `create()` — the key is split with Shamir secret sharing and a recovery share is stored in Shield — only the key generation step is skipped.

:::info\[Key format]

* **Ethereum (EVM)** — hex-encoded private key (`0x` prefix optional).
* **Solana (SVM)** — base58-encoded 64-byte secret key (the same string returned by `exportPrivateKey()` for a Solana wallet).
  :::

:::warning\[Handle private keys with care]
Treat the imported `privateKey` as a high-value secret. Read it from a trusted user-controlled input, avoid logging it, and never persist it in plaintext after import — once imported, all subsequent signing happens through Openfort's MPC flow.
:::

The `import` method accepts the following parameters:

```typescript
import(params: {
  privateKey: string                  // Hex (EVM) or base58 (SVM)
  chainType: ChainTypeEnum            // 'EVM' | 'SVM'
  accountType: AccountTypeEnum        // 'Smart Account' | 'Externally Owned Account' | 'Delegated Account'
  chainId?: number                    // Target chain ID (required for Smart Accounts)
  recoveryParams: RecoveryParams      // Recovery configuration (required)
}): Promise<EmbeddedAccount>
```

It returns the same `EmbeddedAccount` shape as `create` (see [Response type](/docs/products/embedded-wallet/javascript/signer/recovery#response-type)) and emits the `ON_EMBEDDED_WALLET_CREATED` event, so any code listening for wallet creation will pick it up.

**Make sure to wait for the embedded state ready before using the embedded wallets. Learn more about [how to check the embedded state](/docs/products/embedded-wallet/javascript/use-openfort#waiting-for-ready).**

## Recovery method

Importing a wallet stores a recovery share for it, exactly like creating one. Pick a recovery method when importing — it controls how the key is encrypted at rest. See the [recovery methods overview](/docs/products/embedded-wallet/javascript/signer/recovery#decide-a-recovery-method) for help choosing.

### Automatic recovery

Fetch an encryption session from your backend (see the [automatic recovery session guide](/docs/products/embedded-wallet/server/automatic-recovery-session)) and pass it through `recoveryParams`:

:::code-group

```tsx [ImportWallet.tsx]
import openfort from "./openfortConfig"
import getEncryptionSession from "./encryptionSession"
import { RecoveryMethod, AccountTypeEnum, ChainTypeEnum } from '@openfort/openfort-js';

async function importWalletWithAutoRecovery(privateKey: string) {
  const encryptionSession = await getEncryptionSession();

  const account = await openfort.embeddedWallet.import({
    privateKey,
    chainType: ChainTypeEnum.EVM,
    accountType: AccountTypeEnum.SMART_ACCOUNT,
    recoveryParams: {
      recoveryMethod: RecoveryMethod.AUTOMATIC,
      encryptionSession,
    },
  });

  console.log('Wallet imported:', account.address);
  return account;
}
```

```ts [encryptionSession.ts]
const getEncryptionSession = async (): Promise<string> => {
  const response = await fetch('/api/protected-create-encryption-session', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
  });
  const data = await response.json();
  return data.session;
};

export default getEncryptionSession;
```

```ts [openfortConfig.ts]
import { Openfort } from '@openfort/openfort-js';

const openfort = new Openfort({
  baseConfiguration: {
    publishableKey: "YOUR_OPENFORT_PUBLISHABLE_KEY",
  },
  shieldConfiguration: {
    shieldPublishableKey: "YOUR_SHIELD_PUBLISHABLE_KEY",
  },
});

export default openfort;
```

:::

### Password recovery

Have the user supply a password — only they can decrypt the recovery share afterwards. Openfort never sees the password.

:::code-group

```tsx [ImportWallet.tsx]
import openfort from "./openfortConfig"
import { RecoveryMethod, AccountTypeEnum, ChainTypeEnum } from '@openfort/openfort-js';

async function importWalletWithPassword(privateKey: string, password: string) {
  const account = await openfort.embeddedWallet.import({
    privateKey,
    chainType: ChainTypeEnum.EVM,
    accountType: AccountTypeEnum.SMART_ACCOUNT,
    recoveryParams: {
      recoveryMethod: RecoveryMethod.PASSWORD,
      password,
    },
  });

  console.log('Wallet imported:', account.address);
  return account;
}
```

```ts [openfortConfig.ts]
import { Openfort } from '@openfort/openfort-js';

const openfort = new Openfort({
  baseConfiguration: {
    publishableKey: "YOUR_OPENFORT_PUBLISHABLE_KEY",
  },
  shieldConfiguration: {
    shieldPublishableKey: "YOUR_SHIELD_PUBLISHABLE_KEY",
  },
});

export default openfort;
```

:::

### Passkey recovery

Bind the recovery share to a WebAuthn credential. The browser prompts the user to create a passkey (Face ID, Touch ID, fingerprint).

:::warning\[Domain-bound credentials]
WebAuthn credentials are bound to a specific domain (the Relying Party). Credentials created for `example.com` only work on that domain and its subdomains — they cannot be used on other applications.
:::

:::code-group

```tsx [ImportWallet.tsx]
import openfort from "./openfortConfig"
import { RecoveryMethod, AccountTypeEnum, ChainTypeEnum } from '@openfort/openfort-js';

async function importWalletWithPasskey(privateKey: string) {
  const account = await openfort.embeddedWallet.import({
    privateKey,
    chainType: ChainTypeEnum.EVM,
    accountType: AccountTypeEnum.SMART_ACCOUNT,
    recoveryParams: {
      recoveryMethod: RecoveryMethod.PASSKEY,
    },
  });

  console.log('Wallet imported:', account.address);
  return account;
}
```

```ts [openfortConfig.ts]
import { Openfort } from '@openfort/openfort-js';

const openfort = new Openfort({
  baseConfiguration: {
    publishableKey: "YOUR_OPENFORT_PUBLISHABLE_KEY",
  },
  shieldConfiguration: {
    shieldPublishableKey: "YOUR_SHIELD_PUBLISHABLE_KEY",
    // For production, set passkeyRpId to match your domain:
    passkeyRpId: "yourdomain.com",
    passkeyRpName: "Your App Name",
    passkeyDisplayName: "My Wallet",
  },
});

export default openfort;
```

:::

## Importing a Solana wallet

Set `chainType: ChainTypeEnum.SVM` and pass the base58-encoded 64-byte secret key. Solana accounts use `AccountTypeEnum.EOA`:

```tsx
import openfort from "./openfortConfig"
import { RecoveryMethod, AccountTypeEnum, ChainTypeEnum } from '@openfort/openfort-js';

async function importSolanaWallet(privateKey: string, encryptionSession: string) {
  const account = await openfort.embeddedWallet.import({
    privateKey,                                   // base58-encoded 64-byte secret key
    chainType: ChainTypeEnum.SVM,
    accountType: AccountTypeEnum.EOA,
    recoveryParams: {
      recoveryMethod: RecoveryMethod.AUTOMATIC,
      encryptionSession,
    },
  });

  console.log('Solana wallet imported:', account.address);
  return account;
}
```
