跳至主要內容
本頁面使用機器翻譯自英語,可能包含錯誤或不清楚的語言。如需最準確的信息,請參閱英文原文。由於更新頻繁,部分內容可能與英文原文有出入。請加入我們在 Crowdin 上的努力,幫助我們改進本頁面的翻譯。 (Crowdin translation page, Contributing guide)

Address

用於轉換公共地址和公共密鑰的工具。

從**@kaiachain/ethers-ext軟件包中導入getCompressedPublicKey**。

從 "賬戶 "對象中,您可以使用 "address_from_private_key "獲取公共地址,或使用 "compressed_key "獲取壓縮公共密鑰

根據未壓縮公鑰的 xy 座標,可以使用 compressed_key_from_xycompressed_key_and_address_from_xy 獲取公鑰和地址。

address_utils.py

from eth_account import Account
from web3py_ext.klaytn_account.utils import compressed_key_from_xy, address_from_private_key, compressed_key, \
compressed_key_and_address_from_xy
def main():
private_key=Account.from_key("0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8")
print("Public key from private key",address_from_private_key(private_key))
print("Compress key from private key",compressed_key(private_key))
x = "0xdc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd"
y = "0xaf06ca34ae8714cf3dae06bacdb78c7c2d4054bd38961d40853cd5f15955da79"
print("Compress public key from x,y", compressed_key_from_xy(x, y))
print("Compress public key and address from x,y", compressed_key_and_address_from_xy(x, y))
main()

output

❯ python address_utils.py
Public key from private key 0xa2a8854b1802d8cd5de631e690817c253d6a9153
Compress key from private key 0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd
Compress key from x,y 03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd
Compress key and address from x,y ('0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd', '0xA2a8854b1802D8Cd5De631E690817c253d6a9153')

讓這個頁面變得更好