본문으로 건너뛰기
이 페이지는 영문에서 기계 번역되었으므로 오역이나 어색한 표현이 있을 수 있습니다. 따라서 정확한 정보는 영어 원문을 참조하시기 바랍니다. 또한 잦은 업데이트로 인해 일부 콘텐츠는 영문이 그대로 남아있을 수 있습니다. 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

페이지를 개선해 주세요