有没有人知道什么包支持下面的base58到十六进制字符串的转换,或者相反的从十六进制字符串到base58编码的转换。下面是一个python实现的示例。
https://www.reddit.com/r/Tronix/comments/ja8khn/convert_my_address/
此十六进制字符串<- "4116cecf977b1ecc53eed37ee48c0ee58bcddbea5e“应产生以下结果:"TC3ockcvHNmt7uJ8f5k3be1QrZtMzE8MxK”
这是一个用于验证的链接:https://tronscan.org/#/tools/tron-convert-tool
发布于 2021-11-13 11:59:45
我一直在寻找它,并且我能够设计出能够产生所需结果的函数。
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)
# TGnKLLBQyCo6QF911j65ipBz5araDSYQADhttps://stackoverflow.com/questions/66219766
复制相似问题