I tried several ways to get a Taproot address from a Private Key with bitcoinlib, but I kept getting different addresses than those I get with Taproot wallets such as Unisat and OKX Wallet.

Then, after a lot of attempts, I found the command Address.parse and with it I tried to get all the parameters of my address, in order to replicate it.

With much surprise, even if I create a class with the exact same parameters and of course same private keys, the derived address is different.

from bitcoinlib.keys import Key, Address

# keys are for testing purposes
private_key_hex = '25eee8288d42567475d1453843ce57b16b6ba5b6c0661cb2a439fff44c4d455d'
private_key_wif = 'KxVSwjuqNb6qe3KTLsHG5nYA3WFEqrjyKnGbwgHAreiWsqrwffuh'

k = Key(private_key_wif)
public_key_hex = '02fdf741bc2b1efe52873d748ca438798ad0133b25c388bc50423aed26df8ffbd7'
public_key_hex_uncompressed = '04fdf741bc2b1efe52873d748ca438798ad0133b25c388bc50423aed26df8ffbd7db6b1b700bd2475709f586d7a0105d29b0e4a3017b259e01bc32b220342ab33a'

addr = Address.parse('bc1pfkde37d8chuqa6tgwvp7rwmtl7vvd20ql6g5433xxpdah30t7nushrsrlu')

testAddr = Address(
    data = public_key_hex,
    hashed_data = None,
    prefix = 'bc',
    script_type = 'p2tr',
    compressed = None,
    encoding = 'bech32',
    witness_type = 'taproot',
    witver = 1,
    depth = None,
    change = None,
    address_index = None,
    network = 'bitcoin',
    network_overrides = None

I don't know if the problem is that bitcoinlib doesn't have bech32m encoding.

If anyone knows how to solve this issue or knows any workaround, it would be really appreciated!

1 Answer 1


python-bitcoinlib doesn't have Taproot support at all (including bech32m, key tweaking, Taproot trees of scripts) at the time of writing (January 2024). There is an open issue here.

Taproot tweaks an unhashed internal public key which is totally different to pre Taproot where the public key is hashed (P2WPKH) so this python-bitcoinlib code won't generate the correct Taproot address for a particular private key.

  • Any workaround? Is there any solution using python or do you know any libraries in other languages?
    – Tprt
    Commented Jan 9 at 11:32
  • @Tprt: buidl-python has Taproot support github.com/buidl-bitcoin/buidl-python. And the functional tests (Python) in Bitcoin Core have Taproot support. btcd (Go) has Taproot support but it is a bit more than a library (basically an alternative full node implementation) Commented Jan 9 at 11:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.