<p>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 <a href="https://github.com/petertodd/python-bitcoinlib/issues/263" rel="nofollow noreferrer">here</a>.</p>
<p>Taproot <a href="https://bitcoin.stackexchange.com/questions/110402/how-to-tweak-a-public-key-for-taproot">tweaks</a> 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.</p>

CC BY-SA 4.0
2024-01-09T11:32:03.417Z
Any workaround? Is there any solution using python or do you know any libraries in other languages?
Tprt
CC BY-SA 4.0
2024-01-09T11:39:50.767Z
@Tprt: buidl-python has Taproot support https://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)
Michael Folkson
CC BY-SA 4.0
2024-01-08T19:10:31.790Z
2024-01-08T19:10:31.790Z
Michael Folkson
<p>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.</p>
<p>Then, after a lot of attempts, I found the command <code>Address.parse</code> and with it I tried to get all the parameters of my address, in order to replicate it.</p>
<p>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.</p>
<pre><code>from bitcoinlib.keys import Key, Address

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

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

addr = Address.parse('bc1pfkde37d8chuqa6tgwvp7rwmtl7vvd20ql6g5433xxpdah30t7nushrsrlu')
print(addr.as_dict())

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
)
print(testAddr)
</code></pre>
<p>I don't know if the problem is that bitcoinlib doesn't have bech32m encoding.</p>
<p>If anyone knows how to solve this issue or knows any workaround, it would be really appreciated!</p>

<python><taproot><p2tr><python-bitcoinlib>
Unable to get Taproot address using bitcoinlib
Tprt
# Unable to get Taproot address using bitcoinlib

(Asked by: username_0 on 2024-01-08)

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)
#k.info()
public_key_hex = '02fdf741bc2b1efe52873d748ca438798ad0133b25c388bc50423aed26df8ffbd7'
public_key_hex_uncompressed = '04fdf741bc2b1efe52873d748ca438798ad0133b25c388bc50423aed26df8ffbd7db6b1b700bd2475709f586d7a0105d29b0e4a3017b259e01bc32b220342ab33a'

addr = Address.parse('bc1pfkde37d8chuqa6tgwvp7rwmtl7vvd20ql6g5433xxpdah30t7nushrsrlu')
print(addr.as_dict())

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
)
print(testAddr)

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!

**Tags:** python, taproot, p2tr, python-bitcoinlib


---

## 1 answers

### Answer by username_1 on 2024-01-08. Score: 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](https://github.com/petertodd/python-bitcoinlib/issues/263).

Taproot [tweaks](https://bitcoin.stackexchange.com/questions/110402/how-to-tweak-a-public-key-for-taproot) 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.

> **Comments:**
> **username_0**: Any workaround? Is there any solution using python or do you know any libraries in other languages?  
> **username_1**: @username_0: buidl-python has Taproot support https://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)  

---

