Closed
Description
Hi,
I'm trying the example https://github.com/meherett/python-hdwallet/blob/master/examples/from_xpublic_key.py to use with my Ledger Hardware Wallet to get all addresses to watch my balances.
From Ledger Live I go to my Bitcoin account and go to the account settings where I get the following:
{
"xpub": "xpub[xPub-key]",
"index": 0,
"freshAddressPath": "84'/0'/0'/0/9",
"id": "js:2:bitcoin:xpub[xPub-key]:native_segwit",
"blockHeight": 748956
}
And use the following code:
#!/usr/bin/env python3
from hdwallet import HDWallet as HDWallet
from hdwallet.utils import is_root_xpublic_key
from hdwallet.symbols import BTC as SYMBOL
# Strict for root xpublic key
STRICT: bool = False
# Bitcoin root xpublic key
XPUBLIC_KEY: str = "xpub[xPub-key]"
if STRICT:
# Check root xpublic key
assert is_root_xpublic_key(
xpublic_key=XPUBLIC_KEY, symbol=SYMBOL), "Invalid Root XPublic Key."
# Initialize Bitcoin mainnet HDWallet
hdwallet: HDWallet = HDWallet(symbol=SYMBOL)
# Get Bitcoin HDWallet from xpublic key
hdwallet.from_xpublic_key(xpublic_key=XPUBLIC_KEY, strict=False)
for i in range(10):
print('Index {}'.format(str(i)))
hdwallet.from_path("m/84/0/0/0/{}".format(str(i)))
# hdwallet.from_path("m/0/{}".format(str(i)))
print("P2WPKH Address:", hdwallet.p2wpkh_address())
print('')
When I set the STRICT variable to True I get the message "Invalid Root Xpublic Key." When I set it to False I'm able to generate addresses, however I don't get addresses that where generated by Ledger Live.
Did get anyone working code for the xpub with Ledger Live?
Metadata
Assignees
Labels
No labels
Activity