HD Account

Caution

These features are experimental and unaudited

HD Mnemonic module

class eth_account.hdaccount.mnemonic.Mnemonic(raw_language: Language | str = Language.ENGLISH)

Bases: object

Creates and validates BIP39 mnemonics.

>>> from eth_account.hdaccount import Language, Mnemonic

>>> # Create a new Mnemonic instance with Czech language
>>> cz_mnemonic = Mnemonic(Language.CZECH)

>>> # English is the default language
>>> en_mnemonic = Mnemonic()

>>> # List available languages
>>> available_languages = Mnemonic.list_languages()
>>> print(available_languages)
['chinese_simplified', 'chinese_traditional', 'czech', 'english', 'french', 'italian', 'japanese', 'korean', 'spanish']

>>> # List available enumerated languages
>>> available_languages = Mnemonic.list_languages_enum()
>>> print(available_languages)
[<Language.CHINESE_SIMPLIFIED: 'chinese_simplified'>, <Language.CHINESE_TRADITIONAL: 'chinese_traditional'>, <Language.CZECH: 'czech'>, <Language.ENGLISH: 'english'>, <Language.FRENCH: 'french'>, <Language.ITALIAN: 'italian'>, <Language.JAPANESE: 'japanese'>, <Language.KOREAN: 'korean'>, <Language.SPANISH: 'spanish'>]

>>> # Generate a new mnemonic phrase
>>> mnemonic_phrase = en_mnemonic.generate()
>>> print(mnemonic_phrase) 
'cabin raise oven oven knock fantasy flock letter click empty skate volcano'

>>> # Validate a mnemonic phrase
>>> is_valid = en_mnemonic.is_mnemonic_valid(mnemonic_phrase)
>>> print(is_valid)
True

>>> # Convert mnemonic phrase to seed
>>> seed = en_mnemonic.to_seed(mnemonic_phrase, passphrase="optional passphrase")
>>> print(seed) 
b'\x97ii\x07\x12\xf0$\x81\x98\xb6?\x07\x08t7\x18d\x87\xe1\x7f\xbe\xbaL\xb4i%\xeb\x12\xce\xe2h\x1c\xb2\x19\x13\xfb9wtoV\x9c\xb8\xdf;5\xba4X\xa3\xd6b`|\xdc\xb1\x10\xb0\xeeS\x86\x95\xd75'
generate(num_words: int = 12) str

Generate a new mnemonic with the specified number of words.

is_mnemonic_valid(mnemonic: str) bool

Checks if mnemonic is valid

Parameters:

mnemonic (str) – Mnemonic string

static list_languages() List[str]

Returns a list of languages available for the seed phrase

static list_languages_enum() List[Language]

Returns a list of Language objects available for the seed phrase

classmethod to_seed(checked_mnemonic: str, passphrase: str = '') bytes
Parameters:
  • checked_mnemonic (str) – Must be a correct, fully-expanded BIP39 seed phrase

  • passphrase (str) – Encryption passphrase used to secure the mnemonic

Returns bytes:

64 bytes of raw seed material from PRNG

Module contents

eth_account.hdaccount.generate_mnemonic(num_words: int, lang: Language | str) str
eth_account.hdaccount.key_from_seed(seed: bytes, account_path: str) bytes
eth_account.hdaccount.seed_from_mnemonic(words: str, passphrase: str) bytes