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'
- is_mnemonic_valid(mnemonic: str) bool
Checks if mnemonic is valid
- Parameters:
mnemonic (str) – Mnemonic string