본문으로 건너뛰기
This page uses machine translation from English, which may contain errors or unclear language. For the most accurate information, please see the original English version. Some content may be in the original English due to frequent updates. Help us improve this page's translation by joining our effort on Crowdin. (Crowdin translation page, Contributing guide)

Address

Utils for converting public address, public key.

Import the getCompressedPublicKey from @kaiachain/ethers-ext packages

From an Account object you can get the public address with address_from_private_key or get the compressed public key with compressed_key

From x and y coordinates of an uncompressed public key, you can get the public key and the address using compressed_key_from_xy and compressed_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')

페이지를 개선해 주세요