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

キャンセル

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

KAIAの機能をethers.jsに追加するために、ethers と @kaiachain/ethers-ext パッケージをインポートします。

senderfee payerのアドレスと秘密鍵を定義する。

指定されたkairos testnet URLでプロバイダを設定します。 エーテルにおけるプロバイダーとは、ブロックチェーンのデータにアクセスするための読み取り専用の抽象化されたものである。

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

秘密鍵とプロバイダーを使ってsenderのウォレットを作成する。

fee payerのウォレットを秘密鍵とプロバイダーで作成する。

fromフィールドをsender addressとし、typeフィールドをTxType.FeeDelegatedCancel とするトランザクションを宣言する。

senderウォレットでトランザクションに署名し、senderTxHashRLPをプリントアウトする。

手数料支払者のウォレットを使ってブロックチェーンにトランザクションを送信する。 関数 sendTransactionAsFeePayer は送信者の署名に FeePayer の秘密鍵による署名を追加し、ブロックチェーンネットワークに送信する。

wait関数は、ブロックチェーン上でtx受信が完了すれば、それを返す。

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
}

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