# Mnemonic.toPrivateKey

Converts a mnemonic to a private key.

## Imports

:::code-group
```ts [Named]
import { Mnemonic } from 'ox'
```

```ts [Entrypoint]
import * as Mnemonic from 'ox/Mnemonic'
```
:::

## Examples

```ts twoslash
import { Mnemonic } from 'ox'

const mnemonic = Mnemonic.random(Mnemonic.english)
const privateKey = Mnemonic.toPrivateKey(mnemonic)
// @log: '0x...'
```

### Paths

You can derive a private key at a specific path using the `path` option.

```ts twoslash
import { Mnemonic } from 'ox'

const mnemonic = Mnemonic.random(Mnemonic.english)
const privateKey = Mnemonic.toPrivateKey(mnemonic, {
  path: Mnemonic.path({ index: 1 }) // 'm/44'/60'/0'/0/1' // [!code focus]
})
// @log: '0x...'
```

## Definition

```ts
function toPrivateKey<as>(
  mnemonic: string,
  options?: toPrivateKey.Options<as>,
): toPrivateKey.ReturnType<as>
```

**Source:** [src/core/Mnemonic.ts](https://github.com/wevm/ox/blob/main/src/core/Mnemonic.ts#L232)

## Parameters

### mnemonic

* **Type:** `string`

The mnemonic to convert.

### options

* **Type:** `toPrivateKey.Options<as>`
* **Optional**

Conversion options.

#### options.as

* **Type:** `"Bytes" | "Hex" | as`
* **Optional**

The output format.

#### options.passphrase

* **Type:** `string`
* **Optional**

An optional passphrase for additional protection to the seed.

#### options.path

* **Type:** `string`
* **Optional**

An optional path to derive the private key from.

## Return Type

The private key.

`toPrivateKey.ReturnType<as>`
