How would I get the Extended public key as a zpub for a given mnemonic? #977
Replies: 2 comments
-
Thanks for reposting @nondiremanuel I've found a kind of solution now by using the let mnemonic = Mnemonic::parse_in(Language::English, mnemonic_string)?;
let network = Network::Bitcoin;
let secp = Secp256k1::new();
let seed = mnemonic.to_seed("");
let root_xprv = bip32::XPrv::new(&seed)?;
let child_xpub = root_xprv.public_key();
let zpub = child_xpub.to_string(Prefix::ZPUB); This works / gives me a zpub, however the zpub doesn't resolve to the addresses used in my wallet (when checking for balances), and, it is a different zpub from the one that the Electrum wallet shows. So my solution is still wrong somehow and I don't understand why. It would be great if BDK could offer a way to replicate getting zpubs, ypubs, tpubs similar to what Electrum / other wallets are doing. (my use case is using a third party API to find all balances for a given mnemonic in one go) |
Beta Was this translation helpful? Give feedback.
-
Hi Spicefarer. Take a look at this message and the following exchange concerning z/y/v pubs. I think there may or may not be separate crates (probably in various states of "not-so-maintained"? not sure... and I certainly don't recommend them) that add it, but the BDK approach follows rust-bitcoin and doesn't use z/y/v pubs. Using output descriptors removes the requirement for those with much more upside. |
Beta Was this translation helpful? Give feedback.
-
Repost from issue #973 by @spicefarer:
I've been looking into this for hours now and I can't figure out how to get the zpub for a given mnemonic. I'm using this website as a reference.
Here, the given mnemonic (elegant aerobic pony glare science valid tool power toast effort loud bomb) leads to this xpub:
xpub661MyMwAqRbcFnVHjPTLtR5ZHJkg3iHG4uymkHkTPWveNvLxxjjHyAM5RwPstw1rvC1wk2Ls7b38qp9rriGUSwHPwWZhyBf7HkKV9yekFtB
and this zpub (when selecting BIP84):
zpub6jftahH18ngZxNsXQ72bJbGZdF3ZvxGFu92DK5YE9XgQV7yRU44RDHfMUMK3tkKhjUFZEyXz2ukEcPNzJ76W3QebgBxZ91J5qCSmw5AgA1S
I can successfully get the xpub with bdk, but all my attempts at getting an xpub failed. This is my current code:
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions