Bitcoin
Can’t get Taproot address using bitcoinlib – Stack Overflow
I tried several ways to get the Taproot address from my private key using bitcoinlib, but I kept getting different addresses than the addresses I got with Taproot wallets like Unisat and OKX Wallet.
Then, after trying several times, I found the command. Address.parse
And I tried to get all the parameters of my address to replicate it.
Surprisingly, even if you create a class with the same parameters and the same private key, the derived addresses are 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 fix this or has a workaround, I would really appreciate it!