有谁知道有什么软件包支持以下将base58转换为十六进制字符串或从十六进制字符串转换为base58编码的相反方式。 下面是一个 python 实现的示例。
https://www.reddit.com/r/Tronix/comments/ja8khn/convert_my_address/
这个十六进制字符串<-“4116cecf977b1ecc53eed37ee48c0ee58bcddbea5e” 应该导致这样的结果:“TC3ockcvHNmt7uJ8f5k3be1QrZtMzE8MxK”
最佳答案
我一直在寻找它,并且我能够设计出产生所需结果的函数。
import base58
def hex_to_base58(hex_string):
if hex_string[:2] in ["0x", "0X"]:
hex_string = "41" + hex_string[2:]
bytes_str = bytes.fromhex(hex_string)
base58_str = base58.b58encode_check(bytes_str)
return base58_str.decode("UTF-8")
def base58_to_hex(base58_string):
asc_string = base58.b58decode_check(base58_string)
return asc_string.hex().upper()
如果您想将交易的公钥(十六进制)转换为钱包地址(base58),它们非常有用。
public_key_hex = "0x4ab99740bdf786204e57c00677cf5bf8ee766476"
address = hex_to_base58(public_key_hex)
print(address)
# TGnKLLBQyCo6QF911j65ipBz5araDSYQAD
关于r - 转为 base58 的十六进制字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66219766/