1200wd/bitcoinlib

how to get taproot address from singlekey?

Closed this issue · 5 comments

I'm tring to use this code to get a taproot address , but the result I got is different from the address displayed in my unisat wallet.
Address(key.public_hex, script_type='p2tr', encoding='bech32').address

Please check if the unisat wallet is not using a different key path.

And I think it should be like this:

 addr = Address(hashed_data=key.hash160, script_type='p2tr', encoding='bech32').address

Please check if the unisat wallet is not using a different key path.

And I think it should be like this:

 addr = Address(hashed_data=key.hash160, script_type='p2tr', encoding='bech32').address

I used this method, but the address I got was inconsistent with the address shown in my wallet

Did you check the key paths?

I did some tests, and compared to other wallets, but could not find any problems.

Did you check the key paths?

I did some tests, and compared to other wallets, but could not find any problems.

I exported the WIF private key from the unisat wallet and then used the following code to get the taproot address, can you help me see where I might be going wrong?

from bitcoinlib.keys import *
 key = Key(wif_key)
 addr = Address(hashed_data=key.hash160, script_type='p2tr', encoding='bech32').address

I think taproot uses the public key instead of the hashed public key for the address.

Can you try it like this:

from bitcoinlib.keys import *
key = Key(wif_key)
addr = Address(hashed_data=key.public_hash, script_type='p2tr', encoding='bech32').address