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

Legacy Account Key

AccountKeyLegacy

web3py_ext導入extend,將 web3 擴展為 kaia web3

eth_accountweb3py_extcytools 中導入必要的實用程序

使用指定的 kairos 測試網 URL 創建 Web3 實例

此外,您還可以將提供商 URL 從 kairos 更改為 quicknode

從私人密鑰加載賬戶

創建一個TxType.ACCOUNT_UPDATE類型的空交易。 您可以使用 empty_tx 工具來獲取已填寫默認字段的 tx。

使用 merge 工具,將 senderkeys 等附加字段合併到空 tx 中。

在這種情況下,要更新的賬戶密鑰是** legacy**密鑰。

使用 fill_transaction 為交易對象添加更多參數,如 gas 限制...

您可以使用 to_pretty 工具打印格式化的 tx。

簽署賬戶更新 tx 類型。 您必須使用已加載的賬戶簽署

向網絡發送*已簽名的交易,並等待接收,直到交易在區塊鏈中完全執行為止

web3_account_update_legacy.py

from web3py_ext import extend
from web3 import Web3
from eth_account import Account
from web3py_ext.klaytn_account.utils import compressed_key
from web3py_ext.klaytn_account.account_key import KeyType
from web3py_ext.transaction.transaction import (
empty_tx,
fill_transaction,
TxType
)
from web3py_ext.utils.klaytn_utils import (
to_pretty,
bytes_to_hex_str
)
from cytoolz import merge
w3 = Web3(Web3.HTTPProvider(
'https://public-en-kairos.node.kaia.io'
))
def web3_account_update_legacy():
user = Account.from_key('0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8')
account_update_tx = empty_tx(TxType.ACCOUNT_UPDATE)
account_update_tx = merge(account_update_tx, {
'from' : user.address,
'key' : {
'type': KeyType.LEGACY,
'key': {}
}
})
account_update_tx = fill_transaction(account_update_tx, w3)
print(to_pretty(account_update_tx))
# sign the kaia specific transaction type with web3py
signed_tx = Account.sign_transaction(account_update_tx, user.key)
print('\nrawTransaction:', bytes_to_hex_str(signed_tx.rawTransaction))
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print('tx hash: ', tx_hash, 'receipt: ', tx_receipt)
web3_account_update_legacy()

output

❯ py web3_account_update_legacy.py
# {
# "from": "0xA2a8854b1802D8Cd5De631E690817c253d6a9153",
# "gas": 159000,
# "gasPrice": 50000000000,
# "nonce": 990,
# "chainId": 1001,
# "type": 32,
# "key": {
# "type": 1,
# "key": "0x03dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cd"
# }
# }
# rawTransaction: 20f86e8203de850ba43b740083026d1894a2a8854b1802d8cd5de631e690817c253d6a91538201c0f847f8458207f5a0a37fa3b1882109cab6d565b869d217a80bae7ac6dd1b8361729f81925520d48ca0049b1ebfbe19a7b57d8ff0ea965581f6b02c4b5ac0c08b3c1925e030d05d1444
# tx hash: 0x2e1b5ccc12057297db5bac624085532e302ff75b20fb36fe3728efe7a7904ef1 receipt: AttributeDict({'blockHash': HexBytes('0xbb9fc21ef1793f4c03492e2293dfdcc6d4392cd40a781a33fbebf96bbf032490'), 'blockNumber': 150553739, 'contractAddress': None, 'cumulativeGasUsed': 21000, 'effectiveGasPrice': 25000000000, 'from': '0xA2a8854b1802D8Cd5De631E690817c253d6a9153', 'gasUsed': 21000, 'logs': [], 'logsBloom': HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'), 'status': 1, 'to': '0xA2a8854b1802D8Cd5De631E690817c253d6a9153', 'transactionHash': HexBytes('0x2e1b5ccc12057297db5bac624085532e302ff75b20fb36fe3728efe7a7904ef1'), 'transactionIndex': 0, 'type': 0})

讓這個頁面變得更好