Skip to content

Mnemonic.toPrivateKey

Converts a mnemonic to a private key.

Imports

Named
import { Mnemonic } from 'ox'

Examples

import { Mnemonic } from 'ox'
 
const mnemonic = Mnemonic.random(Mnemonic.english)
const privateKey = Mnemonic.toPrivateKey(mnemonic)
'0x...'

Paths

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

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'
})
'0x...'

Definition

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

Source: src/Mnemonic.ts

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>