使用Python計(jì)算TRC20地址
TRC20地址介紹
TRC20地址是一種數(shù)字錢包地址,用于接收或發(fā)送Tether加密貨幣。每個(gè)TRC20地址由一組26到64個(gè)字符組成,通常以0x開頭,后面跟著一系列大寫字母和數(shù)字。如果您想要使用TRC20地址進(jìn)行交易,您需要將其提供給數(shù)字貨幣交易所或其他交易平臺(tái),并按照指示操作即可。
Python計(jì)算TRC20地址
完整代碼
import hashlib
from eth_utils import keccak
import base58
import ecdsa
from tronpy.keys import PrivateKey
def test1():
# 示例私鑰,可替換為你自己的私鑰
private_key_hex = "your_private_key_hex_string"
# 將十六進(jìn)制私鑰轉(zhuǎn)換為字節(jié)形式
private_key_bytes = bytes.fromhex(private_key_hex)
# 使用 SECP256k1 曲線生成私鑰對(duì)象
sk = ecdsa.SigningKey.from_string(private_key_bytes, curve=ecdsa.SECP256k1)
# 從私鑰派生公鑰
vk = sk.get_verifying_key()
public_key_bytes = vk.to_string()
public_key_point = vk.pubkey.point
# Hash the public key using Keccak-256
public_key_hash = keccak(public_key_bytes)
# Take the last 20 bytes of the hash and prepend 0x41
# 添加 TRON 地址前綴 (0x41)
tron_prefix = b'\x41'
prefixed_hash160 = tron_prefix + public_key_hash[-20:]
# 對(duì)添加前綴后的結(jié)果進(jìn)行兩次 SHA-256 哈希以獲取校驗(yàn)和
first_sha256 = hashlib.sha256(prefixed_hash160).digest()
second_sha256 = hashlib.sha256(first_sha256).digest()
# 取前 4 字節(jié)作為校驗(yàn)和
checksum = second_sha256[:4]
# 將前綴、哈希結(jié)果和校驗(yàn)和拼接
full_payload = prefixed_hash160 + checksum
# Convert to hexadecimal string
trc_address_hex = prefixed_hash160.hex()
# 使用 Base58 編碼生成最終的 TRC 地址
trc_address = base58.b58encode(full_payload).decode()
# 打印私鑰(以十六進(jìn)制字符串形式)
print("私鑰 (十六進(jìn)制):", sk.to_string().hex())
# 打印公鑰(以十六進(jìn)制字符串形式)
print("公鑰 (十六進(jìn)制):", vk.to_string().hex())
# 打印公鑰對(duì)應(yīng)的橢圓曲線上的點(diǎn)
print("公鑰對(duì)應(yīng)的橢圓曲線上的點(diǎn):")
print(" x 坐標(biāo) (十六進(jìn)制):", hex(public_key_point.x()))
print(" y 坐標(biāo) (十六進(jìn)制):", hex(public_key_point.y()))
print("Keccak-256哈希:", public_key_hash.hex())
print("校驗(yàn)和:", checksum.hex())
print("完整地址數(shù)據(jù):", full_payload.hex())
print("TRC 地址數(shù)據(jù):", trc_address_hex)
print("TRC 地址:", trc_address)
print('\n')
def test2():
# 指定私鑰(請(qǐng)?zhí)鎿Q為你實(shí)際的私鑰)
private_key_hex = "your_private_key_hex_string"
# 將十六進(jìn)制私鑰轉(zhuǎn)換為PrivateKey對(duì)象
private_key = PrivateKey(bytes.fromhex(private_key_hex))
# 從私鑰派生公鑰
public_key = private_key.public_key
# 從公鑰生成TRC地址
address = public_key.to_base58check_address()
print("指定的私鑰 (十六進(jìn)制):", private_key_hex)
print("公鑰 (十六進(jìn)制):", public_key.hex())
print("TRC地址:", address)
print('\n')
test1()
test2()
到此這篇關(guān)于使用Python計(jì)算TRC20地址的文章就介紹到這了,更多相關(guān)Python計(jì)算TRC20地址內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Pytorch中torch.cat()函數(shù)舉例解析
一般torch.cat()是為了把多個(gè)tensor進(jìn)行拼接而存在的,下面這篇文章主要給大家介紹了關(guān)于Pytorch中torch.cat()函數(shù)舉例解析的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
python?selenium在打開的瀏覽器中動(dòng)態(tài)調(diào)整User?Agent
這篇文章主要介紹的是python?selenium在打開的瀏覽器中動(dòng)態(tài)調(diào)整User?Agent,具體相關(guān)資料請(qǐng)需要的朋友參考下面文章詳細(xì)內(nèi)容,希望對(duì)你有所幫助2022-02-02
Pandas DataFrame中的tuple元素遍歷的實(shí)現(xiàn)
這篇文章主要介紹了Pandas DataFrame中的tuple元素遍歷的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
Python使用SymPy解決Manim曲線繪制速度不均的問題
這段文章詳細(xì)講解了使用SymPy進(jìn)行弧長參數(shù)化以實(shí)現(xiàn)參數(shù)曲線均勻繪制的技術(shù),通過計(jì)算弧長函數(shù)、反解參數(shù)值及數(shù)值求解,實(shí)現(xiàn)曲線繪制節(jié)奏均勻,提升視覺體驗(yàn),關(guān)鍵代碼示例及效果展示進(jìn)一步說明了方法的有效性,需要的朋友可以參考下2026-06-06
使用torchtext導(dǎo)入NLP數(shù)據(jù)集的操作
這篇文章主要介紹了使用torchtext導(dǎo)入NLP數(shù)據(jù)集的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05
Pytorch dataloader在加載最后一個(gè)batch時(shí)卡死的解決
這篇文章主要介紹了Pytorch dataloader在加載最后一個(gè)batch時(shí)卡死的解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-05-05

