I have my Private Keys in Hexadecimal Format and my LTC coin is stored in SegWit Bech32 addresses (ltc1qxpne36*****).
When I try to convert my private hex keys to WIF keys, the WIF keys generates a different address (LgUeq5*****) where I do not have my funds.
How do I acces my segwit address using my hex private keys?
1 Like
There seems to be an issue with the hexadecimal to WIF conversion. You can use a Python library like pycoin to correctly derive the corresponding Wallet Import Format key and its associated address.
With the help of ChatGPT, here is some code that will hopefully resolve your issue.
from pycoin.key import Key
from pycoin.encoding import is_valid_wif, a2b_hashed_base58, b2a_hashed_base58, b2a_base58
def private_key_to_wif(private_key_hex):
# Convert private key from hex to bytes
private_key_bytes = bytes.fromhex(private_key_hex)
# Create a Key object
key = Key(secret_exponent=int.from_bytes(private_key_bytes, byteorder='big'))
# Get the Wallet Import Format (WIF) key
wif_key = key.wif()
return wif_key
def wif_to_address(wif_key):
# Create a Key object from the WIF key
key = Key(wif=wif_key)
# Get the address
address = key.address()
return address
# Replace 'your_private_key_hex' with your actual private key in hexadecimal format
private_key_hex = 'your_private_key_hex'
# Convert private key to WIF
wif_key = private_key_to_wif(private_key_hex)
# Derive address from WIF
derived_address = wif_to_address(wif_key)
print(f"WIF Key: {wif_key}")
print(f"Derived Address: {derived_address}")