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

取消

TxTypeCancel 取消事務池中具有相同 nonce 的事務的執行。 當已提交的交易在一定時間內似乎未得到處理時,這種交易類型就很有用。

Import extend from web3py_ext to extend web3 to kaia web3

Import necessary utils from eth_account, web3py_ext and cytoolz

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

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

從私人密鑰加載賬戶

用私人密鑰加載一個付款人賬戶,代替上述賬戶簽署和發送交易

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

使用 merge 工具將 fromnonce 字段合併到空 tx 中。

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

用用戶的私鑰簽署取消 tx

從已簽署的 tx 中的簽名中恢復signer's address

您可以使用Account.decode_transaction工具對 RLP 編碼的 tx 進行解碼,如果您想讓輸出格式更漂亮,請使用to_pretty工具。

用收費委託人的賬戶簽署原始交易

從簽署的交易中找回繳費人地址

您可以使用Account.decode_transaction工具對 RLP 編碼的 tx 進行解碼,如果您想讓輸出格式更漂亮,請使用to_pretty工具。

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
# raw transaction of signed 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
# }
# raw transaction of feePayer signed tx: 0x39f8c98203a3850ba43b740083026d1894a2a8854b1802d8cd5de631e690817c253d6a9153f847f8458207f5a00eec532ebe17fade46561d3ff503c97e07d8d9ba611b6a7f8a1cc11621dfc03fa006e3ee9cf4f5bfd6674d656c571cfb80b0bfd99bebe87f017e288be7ea4fec2194cb0eb737dfda52756495a5e08a9b37aab3b271daf847f8458207f6a06697d97df68a0c4a2c59b3d7a8c5c479a6b43e7a34394518b858ef908d10b76aa0492c8da32c77a71ce26650f9ac842496bb33f0f17877ce1b23e1763b7c87e28d
# recovered feepayer address: ['0xCb0eb737dfda52756495A5e08A9b37AAB3b271dA']
# decoded transaction: {
# "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
# }

讓這個頁面變得更好