What am I doing wrong here? I'm trying to generate bitcoin addresses from the seed but they do not match with ones from electrum application. Did I miss something? And I also have trouble with generating wifs, as it seems they removed method bitcoin.SecretToASecret(prv, compressed=True), but I can't find with what they replaced it.

from electrum import bitcoin
from electrum import keystore
from electrum.mnemonic import Mnemonic

defaultseed = "face circle glad valley exhibit find man oblige kingdom scorpion fish misery"

m44_0_0_0_0 = {
    'address': '1ALSQR3C68JLj5rtJHv594r5cviTqoXMNr',  # compressed by default
    'private_key': 'Ky9mddDtaqcLC1vv6egmgQpiZh8Lgh111LnJSyJENxJs3oW93bjD'

if __name__ == '__main__':

    password = ''
    bip32_seed = Mnemonic.mnemonic_to_seed(defaultseed, password)

    # m / purpose' / coin_type' / account' / change / address_index
    derivation = "m/44'/0'/0'/"
    xtype = keystore.xtype_from_derivation(derivation)
    # print('seed: {}'.format(repr(bip32_seed)))
    xprv, xpub = bitcoin.bip32_root(bip32_seed, xtype)
    # print('root: {0}  {1}'.format(xprv, xpub))

    xprv, xpub = bitcoin.bip32_private_derivation(xprv, 'm/', derivation)  # 1st account

    # generate first receiving addresses:
    i = 0
    prv, pub = bitcoin.bip32_private_derivation(xprv, "", "0/{index}".format(index=i))

    pub = bitcoin.deserialize_xkey(pub, False)[-1]
    prv = bitcoin.deserialize_xkey(prv, True)[-1]
    addr = bitcoin.public_key_to_p2pkh(pub)

    wif = 'how to generate wif from {prv} using electrum'

    print('{index:2}: {addr}  {wif}'.format(index=i, addr=addr, wif=wif))

1 Answer 1


The derivation path you used is incorrect. Electrum does not use bip44. Anyway here's one way to do this for p2pkh addresses:

from electrum import bitcoin
from electrum import keystore

seed = "<seed here>"
change = False
address_index = 0

k = keystore.from_seed( seed, '', False )
print( bitcoin.pubkey_to_address('p2pkh', k.derive_pubkey( change, address_index ) ) )
  • 1
    Greetings! Are you able to successfully import electrum into python, load a wallet, connect to the Official BTC network, and the list the balance of said wallet? I can't seem to figure out how to do that after spending a lot of time looking at their docs. the quick_start in scripts seems very helpful but it connects to a test-net and not the actual bitcoin network. Commented Jul 1, 2020 at 4:28
  • @frogeyedpeas you should probably ask for help with that in #electrum irc channel on freenode.
    – Abdussamad
    Commented Jul 2, 2020 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.