Skip to content

Instantly share code, notes, and snippets.

@romanz
Last active May 23, 2021 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save romanz/4b32782bfc0ff4984713 to your computer and use it in GitHub Desktop.
Save romanz/4b32782bfc0ff4984713 to your computer and use it in GitHub Desktop.
Creates public and private keys from Electrum 2.0 seed
#!/usr/bin/env python
''' Run from "electrum/lib" directory.
'''
import bitcoin, mnemonic
mn = raw_input("Enter mnemonic (13 words)").strip()
s = mnemonic.Mnemonic.mnemonic_to_seed(mn, '')
print 'seed:', repr(s)
xprv, xpub = bitcoin.bip32_root(s)
print 'root:', xprv, xpub
xprv, xpub = bitcoin.bip32_private_derivation(xprv, "m/", "m/44'/0'")
print 'master:', xprv, xpub
xprv, xpub = bitcoin.bip32_private_derivation(xprv, "", "0'") # 1st account
print 'account #0:', xprv, xpub
# generate first receiving addresses (not change = #0)
for i in range(10):
prv, pub = bitcoin.bip32_private_derivation(xprv, "", "0/%d" % (i,))
pub = bitcoin.deserialize_xkey(pub)[-1]
prv = bitcoin.deserialize_xkey(prv)[-1]
addr = bitcoin.public_key_to_bc_address(pub)
wif = bitcoin.SecretToASecret(prv, compressed=True)
print '%4d: %s %s' % (i, addr, wif)
@y
Copy link

y commented Aug 9, 2015

The addresses produced by this don't match the addresses when running electrum restore, Tested on 2.3.2

@kumrzz
Copy link

kumrzz commented Jul 31, 2016

yes so I have cloned & altered it slightly to work with the current implementation in Electrum 2.7:
https://gist.github.com/kumrzz/9ca3fe4fcdf39ebd4a862154c5c2ddb3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment