2

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

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 ) ) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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