跳至主要内容
本页面使用机器翻译自英语,可能包含错误或不清楚的语言。如需最准确的信息,请参阅英文原文。由于更新频繁,部分内容可能与英文原文有出入。请加入我们在 Crowdin 上的努力,帮助我们改进本页面的翻译。 (Crowdin translation page, Contributing guide)

Cancel

TxTypeCancel 取消事务池中具有相同 nonce 的事务的执行。 当已提交的交易在一定时间内似乎未得到处理时,这种交易类型就很有用。

导入 ethers@kaiachain/ethers-ext 软件包,在 ethers.js 上添加 kaia 功能

定义发送方付费方地址和私人密钥

使用指定的 kairos 测试网 URL 设置提供程序。 以太坊中的提供者是访问区块链数据的只读抽象。

此外,您还可以将提供商 URL 从 kairos 更改为 quicknode

用私钥和提供商创建发送方的钱包

用私钥和提供商创建付费者的钱包

声明一个事务,其from字段为发送地址type字段为TxType.FeeDelegatedCancel。·

发送方钱包签署交易,并打印出发送方TxHashRLP

使用付费者的钱包将交易发送到区块链上。 函数 "sendTransactionAsFeePayer "会在发送者的签名上添加一个带有 FeePayer 私钥的签名,并将其传输到区块链网络。

如果已在区块链中完成发送,wait函数将返回发送回执。

TxFeeDelegatedCancelType.js

const ethers = require("ethers");
const { Wallet, TxType, parseKlay } = require("@kaiachain/ethers-ext");
const senderAddr = "0xa2a8854b1802d8cd5de631e690817c253d6a9153";
const senderPriv = "0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8";
const feePayerAddr = "0xcb0eb737dfda52756495a5e08a9b37aab3b271da";
const feePayerPriv = "0x9435261ed483b6efa3886d6ad9f64c12078a0e28d8d80715c773e16fc000cff4";
const provider = new ethers.providers.JsonRpcProvider("https://public-en-kairos.node.kaia.io");
const senderWallet = new Wallet(senderPriv, provider);
const feePayerWallet = new Wallet(feePayerPriv, provider);
async function main() {
const tx = {
type: TxType.FeeDelegatedCancel,
from: senderAddr,
};
// Sign transaction by sender
const populatedTx = await senderWallet.populateTransaction(tx);
const senderTxHashRLP = await senderWallet.signTransaction(populatedTx);
console.log("senderTxHashRLP", senderTxHashRLP);
// Sign and send transaction by fee payer
const sentTx = await feePayerWallet.sendTransactionAsFeePayer(senderTxHashRLP);
console.log("sentTx", sentTx.hash);
const receipt = await sentTx.wait();
console.log("receipt", receipt);
}
main();

output

❯ node TxFeeDelegatedCancelType.js
senderTxHashRLP 0x39f86a8203af850ba43b740082cd1494a2a8854b1802d8cd5de631e690817c253d6a9153f847f8458207f5a06c639b8828bb27b36b2575636b4ec9dd4c7de4820327fe158746d03b28b90d8ba0332b43ec974ecb3ea16593760cb6e139a95d4ce03847681fb053a00143eb91a1
sentTx 0xd81cd9190f2fd40f6b2e6472f91b95a1e09e2ad3dfc41a6b3458274eb5c9175c
receipt {
to: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
from: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
contractAddress: null,
transactionIndex: 1,
gasUsed: BigNumber { _hex: '0x7918', _isBigNumber: true },
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
blockHash: '0x02d655e716e1a5c8d497f66a6d80683c633d3e4002a9e26026f101983d951c1a',
transactionHash: '0xd81cd9190f2fd40f6b2e6472f91b95a1e09e2ad3dfc41a6b3458274eb5c9175c',
logs: [],
blockNumber: 148732476,
confirmations: 3,
cumulativeGasUsed: BigNumber { _hex: '0x034b1d', _isBigNumber: true },
effectiveGasPrice: BigNumber { _hex: '0x05d21dba00', _isBigNumber: true },
status: 1,
type: 0,
byzantium: true
}

让这个页面变得更好