Skip to content

Instantly share code, notes, and snippets.

@igorgue
Last active February 19, 2020 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorgue/7a029f67bcbcdeabfb880145698b6057 to your computer and use it in GitHub Desktop.
Save igorgue/7a029f67bcbcdeabfb880145698b6057 to your computer and use it in GitHub Desktop.
from electrum.bitcoin import pubkey_to_address
from electrum.constants import BitcoinTestnet
from electrum.keystore import BIP32Node
# Mnemonic: combine defy review meadow hamster future sphere awake upper garbage aunt fish exact minute width
# HD Path: m/49'/1'/0'
xpub = 'upub5DiY8ttzMX33hN2pEFPvdhgucA32AQ58QnHw7Doy9jWDThfZK8RZL1rCkqUBgBLWyc8unNABCdqm6zPFXFiqNzBNQHqFMhXhenqHHAQxyNN'
node = BIP32Node.from_xkey(xpub, net=BitcoinTestnet())
assert xpub == node.to_xkey(net=BitcoinTestnet())
first_addr_node = node.subkey_at_public_derivation("0/0")
address = pubkey_to_address(txin_type='p2wpkh-p2sh', pubkey=first_addr_node.eckey.get_public_key_hex(), net=BitcoinTestnet())
assert address == '2NBo3VLe28bdX5frFojkJEC3yUT7bNri2VB'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment