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

キャンセル

TxTypeCancelは、トランザクションプール内の同じnonceを持つトランザク ションの実行をキャンセルする。 このトランザクション・タイプは、送信されたトランザクションが一定時間未処理のように見える場合に有用である。

web3をkaia web3に拡張するために、web3py_extからextendをインポートする。

eth_accountweb3py_ext、*cytoolz**から必要なutilsをインポートする。

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

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

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

上記アカウントの代わりに、秘密鍵から料金支払者アカウントを読み込んで署名し、トランザクションを送信する。

TxType.FEE_DELEGATED_CANCEL型の空のトランザクションを作成する。 empty_txユーティリティを使えば、デフォルトのフィールドが埋められたtxを得ることができる。

fromフィールドとnonceフィールドを、mergeユーティリティを使用して空のtxにマージする。

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

ユーザーの秘密鍵でcancel txに署名する。

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

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

手数料デリゲータのアカウントで生トランザクションに署名する。

署名されたトランザクションから料金支払者の住所を復元する。

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

web3_fee_delegated_cancel_sign_recover.py

from web3py_ext import extend
from web3 import Web3
from eth_account import Account
from web3py_ext.transaction.transaction import (
empty_tx,
fill_transaction,
TX_TYPE_FEE_DELEGATED_CANCEL
)
from web3py_ext.utils.klaytn_utils import to_pretty
from cytoolz import merge
w3 = Web3(Web3.HTTPProvider('https://public-en-kairos.node.kaia.io'))
def web3_fee_delegated_cancel_sign_recover():
user = Account.from_key('0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8')
fee_delegator = Account.from_key('0x9435261ed483b6efa3886d6ad9f64c12078a0e28d8d80715c773e16fc000cff4')
cancel_tx = empty_tx(TX_TYPE_FEE_DELEGATED_CANCEL)
cancel_tx = merge(cancel_tx, {
'from' : user.address,
})
cancel_tx = fill_transaction(cancel_tx, w3)
# sign the kaia specific transaction type with web3py
signed_tx = Account.sign_transaction(cancel_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))
feepayer_signed_tx = Account.sign_transaction_as_feepayer(signed_tx.rawTransaction, fee_delegator.address, fee_delegator.key)
print("\nraw transaction of feePayer signed tx:", feepayer_signed_tx.rawTransaction.hex())
feepayer_recovered_tx = Account.recover_transaction_as_feepayer(feepayer_signed_tx.rawTransaction)
print("recovered feepayer address:", feepayer_recovered_tx)
decoded_tx = Account.decode_transaction(feepayer_signed_tx.rawTransaction)
print("\ndecoded transaction:", to_pretty(decoded_tx))
web3_fee_delegated_cancel_sign_recover()

output

❯ py web3_fee_delegated_cancel_sign_recover.py
# 署名付きtxの生トランザクション:0x39f86b8203a3850ba43b740083026d1894a2a8854b1802d8cd5de631e690817c253d6a9153f847f8458207f5a00eec532ebe17fade46561d3ff503c97e07d8d9ba611b6a7f8a1cc11621dfc03fa006e3ee9cf4f5bfd6674d656c571cfb80b0bfd99bebe87f017e288be7ea4fec21
# recovered sender address 0xA2a8854b1802D8Cd5De631E690817c253d6a9153
# decoded transaction:{
# "type":57,
# "nonce":931,
# "gasPrice":50000000000,
# "gas":159000,
# "from":"0xA2a8854b1802D8Cd5De631E690817c253d6a9153",
# "signatures":[
# {
# "v":2037,
# "r":6749929892576958642714739615979538685230067780127794094925331144130783330367,
# "s":3116598222383802394999638931088885558560578183897443089888519072063383661601
# }.
# ],
# "chainId":1001
# }.
# feePayerの生トランザクション:0x39f8c98203a3850ba43b740083026d1894a2a8854b1802d8cd5de631e690817c253d6a9153f847f8458207f5a00eec532ebe17fade46561d3ff503c97e07d8d9ba611b6a7f8a1cc11621dfc03fa006e3ee9cf4f5bfd6674d656c571cfb80b0bfd99bebe87f017e288be7ea4fec2194cb0eb737dfda52756495a5e08a9b37aab3b271daf847f8458207f6a06697d97df68a0c4a2c59b3d7a8c5c479a6b43e7a34394518b858ef908d10b76aa0492c8da32c77a71ce26650f9ac842496bb33f0f17877ce1b23e1763b7c87e28d
# recover feepayer address:['0xCb0eb737dfda52756495A5e08A9b37AAB3b271dA']
# デコードされたトランザクション:{
# "type":57,
# "nonce":931,
# "gasPrice":50000000000,
# "gas":159000,
# "from":"0xA2a8854b1802D8Cd5De631E690817c253d6a9153",
# "feePayer":"0xCb0eb737dfda52756495A5e08A9b37AAB3b271dA",
# "signatures":[
# {
# "v":2037,
# "r":6749929892576958642714739615979538685230067780127794094925331144130783330367,
# "s":3116598222383802394999638931088885558560578183897443089888519072063383661601
# }.
# ],
# "feePayerSignatures":[
# {
# "v":2038,
# "r":46404205537188908000560167654303187399733564148219565625489961916532872230762,
# "s":33097556762817862610763009383178378013466927896867683158585566455859245474445
# }.
# ],
# "chainId":1001
# }.

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