> **Can't find what you're looking for?** Use `search_docs` on the docs MCP server at `https://v3.viem.sh/api/mcp` to find what you need.

# Mnemonic

:::info
`Mnemonic` is a re-export of ox's [`Mnemonic`](https://oxlib.sh/api/Mnemonic). Refer to the ox documentation for the full reference.
:::

Utility functions for generating and working with [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) mnemonics.

:::info
The `Mnemonic` module is a friendly wrapper over [`@scure/bip39`](https://github.com/paulmillr/scure-bip39), an **audited** implementation of [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki)
:::

## Examples

Below are some examples demonstrating common usages of the `Mnemonic` module:

* [Generating a Random Mnemonic](#generating-a-random-mnemonic)

* [Converting to Private Key](#converting-to-private-key)

* [Converting to HD Key](#converting-to-hd-key)

* [Converting to Seed](#converting-to-seed)

### Generating a Random Mnemonic

Random mnemonics can be generated using [`Mnemonic.random`](/docs/utilities/mnemonic/random):

```ts twoslash
// @noErrors
import { Mnemonic } from 'viem/utils'

const mnemonic = Mnemonic.random(Mnemonic.english)
// @log: 'buyer zoo end danger ice capable shrug naive twist relief mass bonus'
```

### Converting to Private Key

Mnemonics can be converted to a private key using [`Mnemonic.toPrivateKey`](/docs/utilities/mnemonic/toPrivateKey):

```ts twoslash
// @noErrors
import { Mnemonic } from 'viem/utils'

const privateKey = Mnemonic.toPrivateKey(
  'buyer zoo end danger ice capable shrug naive twist relief mass bonus'
)
// @log: '0x...'
```

### Converting to HD Key

Mnemonics can be converted to a HD Key using [`Mnemonic.toHdKey`](/docs/utilities/mnemonic/toHdKey):

```ts twoslash
// @noErrors
import { Mnemonic } from 'viem/utils'

const hdKey = Mnemonic.toHdKey(
  'buyer zoo end danger ice capable shrug naive twist relief mass bonus'
)
```

### Converting to Seed

Mnemonics can be converted to a master seed using [`Mnemonic.toSeed`](/docs/utilities/mnemonic/toSeed):

```ts twoslash
// @noErrors
import { Mnemonic } from 'viem/utils'

const mnemonic =
  'buyer zoo end danger ice capable shrug naive twist relief mass bonus'
const seed = Mnemonic.toSeed(mnemonic)
// @log: Uint8Array [...64 bytes]
```

## Functions

| Name                | Description                         |
| ------------------- | ----------------------------------- |
| [`Mnemonic.path`](/docs/utilities/mnemonic/path) | Creates an Ethereum-based BIP-44 HD path. |
| [`Mnemonic.random`](/docs/utilities/mnemonic/random) | Generates a random mnemonic. |
| [`Mnemonic.toHdKey`](/docs/utilities/mnemonic/toHdKey) | Converts a mnemonic to a HD Key. |
| [`Mnemonic.toPrivateKey`](/docs/utilities/mnemonic/toPrivateKey) | Converts a mnemonic to a private key. |
| [`Mnemonic.toSeed`](/docs/utilities/mnemonic/toSeed) | Converts a mnemonic to a master seed. |
| [`Mnemonic.validate`](/docs/utilities/mnemonic/validate) | Checks if a mnemonic is valid, given a wordlist. |
