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

Cancel

TxTypeCancel cancels the execution of the transaction with the same nonce in the transaction pool. This transaction type is useful when a submitted transaction seems unprocessed for a certain amount of time.

Import @kaiachain/viem-ext packages to add kaia features on web3

Specify the kairos chain configuration to connect to the Kaia Kairos testnet.

Set up a wallet client using createWalletClient, configured with the Kairos chain, an HTTP transport, and the sender’s private key converted to an account.

Create a transaction request for the cancel transaction using prepareTransactionRequest, specifying the transaction type and sender account.

Sign and send the cancel transaction to the Kaia blockchain using the wallet client’s sendTransaction method, and log the transaction hash.

TxCancelType.js

import { createWalletClient, http, privateKeyToAccount, TxType } from "@kaiachain/viem-ext";
import { kairos } from "viem/chains";
const senderWallet = createWalletClient({
chain: kairos,
transport: http(),
account: privateKeyToAccount(
"0x0e4ca6d38096ad99324de0dde108587e5d7c600165ae4cd6c2462c597458c2b8"
),
});
// Example usage
(async () => {
const txRequest = await senderWallet.prepareTransactionRequest({
account: senderWallet.account,
type: TxType.Cancel,
});
console.log("txRequest", txRequest);
const sentTx = await senderWallet.sendTransaction(txRequest);
console.log("Cancel tx", sentTx);
})();

output

❯ node TxCancelType.js
txRequest {
account: {
address: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
nonceManager: undefined,
sign: [AsyncFunction: sign],
signAuthorization: [AsyncFunction: signAuthorization],
signMessage: [AsyncFunction: signMessage],
signTransaction: [AsyncFunction: signTransaction],
signTypedData: [AsyncFunction: signTypedData],
source: 'privateKey',
type: 'local',
publicKey: '0x04dc9dccbd788c00fa98f7f4082f2f714e799bc0c29d63f04d48b54fe6250453cdaf06ca34ae8714cf3dae06bacdb78c7c2d4054bd38961d40853cd5f15955da79'
},
type: 56,
from: '0xA2a8854b1802D8Cd5De631E690817c253d6a9153',
nonce: 2385,
chainId: 1001,
gas: 53000n,
gasPrice: '0x66720b300',
gasLimit: 132500
}
Cancel tx 0x1bc6db276a8bc2395fcbcd3efd96afba7cf4b5cbcfd18f6bdde541d04838d065

讓這個頁面變得更好