本文へスキップ

legacy

このページは英語からの機械翻訳を使用しており、誤りや不明瞭な表現が含まれている可能性があります。最も正確な情報については、オリジナルの英語版をご覧ください。頻繁な更新のため、一部のコンテンツはオリジナルの英語になっている可能性があります。Crowdinでの取り組みに参加して、このページの翻訳改善にご協力ください。 (Crowdin translation page, Contributing guide)

TxTypeLegacyTransactionは、kaiaに以前存在したトランザクションのタイプを表す。

**このタイプのトランザクションは、アカウントの作成、トークンの転送、スマート・コントラクトのデプロイ、スマート・コントラクトの実行、または前述の混合を実行できる。

web3py_ext から extend をインポートして、web3 を kaia web3 に拡張します。 この場合、Web3.to_pebのようなkaia特有のutilを使いたい場合は、Web3.to_pebを拡張する必要があります。

必要なutilsをeth_account, web3py_extからインポートする。

指定されたkairosテストネットURLでWeb3インスタンスを作成する

また、プロバイダのURLをkairosからquicknodeに変更することができます。

秘密鍵からアカウントを読み込む

fromtovalueフィールドのみを持つlegacy txを定義する。 単位コンバーターを使用 Web3.to_peb

fill_transactionを使用して、トランザクション・オブジェクトにガス・リミットなどのパラメータを追加する。

レガシーtxをユーザーの秘密鍵で署名する。

署名されたTxの署名から署名者のアドレスを復元する。

RLPエンコードされたtxはAccount.decode_transactionユーティリティでデコードできます。

ブロックチェーンに送信する。 このハッシュは受信を待つために使用される。

wait_for_transaction_receiptメソッドは、ブロックチェーンで完了した場合、txレシートを返す。

最後に結果を出します。

txTypeLegacyTransaction.py

from web3py_ext import extend
from web3 import Web3
from eth_account import Account
from web3py_ext.transaction.transaction import (
fill_transaction,
)
from web3py_ext.utils.klaytn_utils import to_pretty
w3 = Web3(Web3.HTTPProvider(
'https://public-en-kairos.node.kaia.io'
))
def web3_legacy_value_transfer_sign_recover():
user = Account.from_key('0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8')
value_transfer_tx = {
'from' : user.address,
'to' : user.address, # to self
'value' : Web3.to_peb(10, "klay"),
}
value_transfer_tx = fill_transaction(value_transfer_tx, w3)
signed_tx = Account.sign_transaction(value_transfer_tx, user.key)
print("\nraw transaction of signed tx:", signed_tx.rawTransaction.hex())
recovered_tx = Account.recover_transaction(signed_tx.rawTransaction)
print("\nrecovered sender address", recovered_tx)
decoded_tx = Account.decode_transaction(signed_tx.rawTransaction)
print("\ndecoded transaction:", to_pretty(decoded_tx))
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_legacy_value_transfer_sign_recover()

output

❯ txTypeLegacyTransaction.py
署名付きtxの生トランザクション:0x02f8738203e982036480850ba43b740082f61894a2a8854b1802d8cd5de631e690817c253d6a9153888ac7230489e8000080c080a0bf6b983904416f360b1563a92e162d15cd67efb22593873f63ccee150f4e1547a02fa3f5582c060e94b73b1cafdfa662fca93866484ef0953c06aa99d1aeceb491
recovered sender address 0xA2a8854b1802D8Cd5De631E690817c253d6a9153
decoded transaction:{
"chainId":1001,
"to":"0xA2a8854b1802D8Cd5De631E690817c253d6a9153",
"value": 1000000000000000,
"data":"0x",
"accessList":[],
"nonce":868,
"maxPriorityFeePerGas":0,
"maxFeePerGas":50000000000,
"gas":63000,
"v":0,
"r":86581857317945006820941358514738363124805940633281219922143445788962711278919,
"s":21548393259938899817541519708353317088336325701153952868361768013661633164433,
"type":2
}
tx hash: b'y\xe4+\xff\x8b\xed\x11D\xd9N\x85\xd4\x0f3\r\x82+\x8d\xc4$3\xaek\xc0\x0b\x81\x97\x8f\xd1\xeb\xb5\xd1' 受信: AttributeDict({'blockHash':HexBytes('0x53b38f1b5a53f67d34ab648581ae7425f1915e49ca3869ae14c56df405791a02'), 'blockNumber':147332771, 'contractAddress':None, 'cumulativeGasUsed':557368, 'effectiveGasPrice': 25000000000, 'from': '0xA2a8854b1802D8Cd5De631E690817c253d6a9153', 'gasUsed': 21000, 'logs': [], 'logsBloom':HexBytes('0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'),'status':1, 'to': '0xA2a8854b1802D8Cd5De631E690817c253d6a9153', 'transactionHash':HexBytes('0x79e42bff8bed1144d94e85d40f330d822b8dc42433ae6bc00b81978fd1ebb5d1'), 'transactionIndex':3, 'type': 2})

ページを改善してください。