0

I have a regtest bitcoin environment with nodes and wallets. I'm running bitcoind and bitcoin-cli, version v0.21.0.0.

So in my node i created my wallet with a bitcoin-cli -regtest createwallet node1 "w1", my question is, how can i import my wallet into https://bitcoinlib.readthedocs.io/en/latest/source/bitcoinlib.wallets.html ?

I thought that I had to export my master key, with something like:

bitcoin-cli dumpwallet /tmp/wallet.dump >/dev/null && grep "extended private masterkey" /tmp/wallet.dump

And dump a private key with:

bitcoin-cli -regtest dumpprivkey $(bitcoin-cli -regtest getnewaddress)

Then would just matter of use them to create a new wallet like:


from bitcoinlib.wallets import Wallet, wallet_create_or_open, HDKey

# all data from regtest, no leak or so ever

private_keys = [
    # priv key
    "cPErqVBuHrWSAtqvRwHu3ZF9vbGJYnE3C1DmAL8RUgGLkRJsLh5y",
]
# regtest and testnet are the same
# the imported_key is the master key extracted with dumpprivkey.

hd_key = 
HDKey(import_key="tprv8ZgxMBicQKsPf98zVnDSA3CH5LvexysRGWq1MGUdR6xTLrky41yhJ3j4RaSdXDFHi7L6KWwoozYcHTufX3y75NxuyVu7oSQE7KsPXoXFAcx", network="testnet", key=private_keys[1])

w = wallet_create_or_open("node_1", keys=hd_key, network="testnet")
print(w.addresslist())

Which prints me an address, but in a totally different format, stating with mxxxx therefore WIF, instead of bcxxx segwit.. which makes me unsure if I'm doing the right thing

Question:

Any documented way to migrate bitcoin core wallets (which i believe are segwit) to bitcoinlib format?

Your Answer

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

Browse other questions tagged or ask your own question.